github.com/hms58/moby@v1.13.1/api/server/router/checkpoint/checkpoint_routes.go (about)

     1  package checkpoint
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  
     7  	"github.com/docker/docker/api/server/httputils"
     8  	"github.com/docker/docker/api/types"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    13  	if err := httputils.ParseForm(r); err != nil {
    14  		return err
    15  	}
    16  
    17  	var options types.CheckpointCreateOptions
    18  
    19  	decoder := json.NewDecoder(r.Body)
    20  	if err := decoder.Decode(&options); err != nil {
    21  		return err
    22  	}
    23  
    24  	err := s.backend.CheckpointCreate(vars["name"], options)
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	w.WriteHeader(http.StatusCreated)
    30  	return nil
    31  }
    32  
    33  func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    34  	if err := httputils.ParseForm(r); err != nil {
    35  		return err
    36  	}
    37  
    38  	checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
    39  		CheckpointDir: r.Form.Get("dir"),
    40  	})
    41  
    42  	if err != nil {
    43  		return err
    44  	}
    45  
    46  	return httputils.WriteJSON(w, http.StatusOK, checkpoints)
    47  }
    48  
    49  func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    50  	if err := httputils.ParseForm(r); err != nil {
    51  		return err
    52  	}
    53  
    54  	err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{
    55  		CheckpointDir: r.Form.Get("dir"),
    56  		CheckpointID:  vars["checkpoint"],
    57  	})
    58  
    59  	if err != nil {
    60  		return err
    61  	}
    62  
    63  	w.WriteHeader(http.StatusNoContent)
    64  	return nil
    65  }