github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/server/router/volume/volume_routes.go (about)

     1  package volume
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  
     7  	"github.com/docker/docker/api/server/httputils"
     8  	"github.com/docker/engine-api/types"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  func (v *volumeRouter) 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, warnings, err := v.backend.Volumes(r.Form.Get("filters"))
    18  	if err != nil {
    19  		return err
    20  	}
    21  	return httputils.WriteJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes, Warnings: warnings})
    22  }
    23  
    24  func (v *volumeRouter) 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  	volume, err := v.backend.VolumeInspect(vars["name"])
    30  	if err != nil {
    31  		return err
    32  	}
    33  	return httputils.WriteJSON(w, http.StatusOK, volume)
    34  }
    35  
    36  func (v *volumeRouter) 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 := v.backend.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 (v *volumeRouter) 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 := v.backend.VolumeRm(vars["name"]); err != nil {
    62  		return err
    63  	}
    64  	w.WriteHeader(http.StatusNoContent)
    65  	return nil
    66  }