github.com/a4a881d4/docker@v1.9.0-rc2/api/server/router/local/volume.go (about)

     1  package local
     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 *router) getVolumesList(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  	volumes, err := s.daemon.Volumes(r.Form.Get("filters"))
    18  	if err != nil {
    19  		return err
    20  	}
    21  	return httputils.WriteJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes})
    22  }
    23  
    24  func (s *router) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    25  	if err := httputils.ParseForm(r); err != nil {
    26  		return err
    27  	}
    28  
    29  	v, err := s.daemon.VolumeInspect(vars["name"])
    30  	if err != nil {
    31  		return err
    32  	}
    33  	return httputils.WriteJSON(w, http.StatusOK, v)
    34  }
    35  
    36  func (s *router) postVolumesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    37  	if err := httputils.ParseForm(r); err != nil {
    38  		return err
    39  	}
    40  
    41  	if err := httputils.CheckForJSON(r); err != nil {
    42  		return err
    43  	}
    44  
    45  	var req types.VolumeCreateRequest
    46  	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
    47  		return err
    48  	}
    49  
    50  	volume, err := s.daemon.VolumeCreate(req.Name, req.Driver, req.DriverOpts)
    51  	if err != nil {
    52  		return err
    53  	}
    54  	return httputils.WriteJSON(w, http.StatusCreated, volume)
    55  }
    56  
    57  func (s *router) deleteVolumes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    58  	if err := httputils.ParseForm(r); err != nil {
    59  		return err
    60  	}
    61  	if err := s.daemon.VolumeRm(vars["name"]); err != nil {
    62  		return err
    63  	}
    64  	w.WriteHeader(http.StatusNoContent)
    65  	return nil
    66  }