mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
94e3b0f428
This patch removes the internal context package and uses golang's package instead. Signed-off-by: Tibor Vass <tibor@docker.com>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (s *Server) getVolumesList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
volumes, err := s.daemon.Volumes(r.Form.Get("filters"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return writeJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes})
|
|
}
|
|
|
|
func (s *Server) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
v, err := s.daemon.VolumeInspect(vars["name"])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return writeJSON(w, http.StatusOK, v)
|
|
}
|
|
|
|
func (s *Server) postVolumesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := checkForJSON(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
var req types.VolumeCreateRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return err
|
|
}
|
|
|
|
volume, err := s.daemon.VolumeCreate(req.Name, req.Driver, req.DriverOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return writeJSON(w, http.StatusCreated, volume)
|
|
}
|
|
|
|
func (s *Server) deleteVolumes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
return err
|
|
}
|
|
if err := s.daemon.VolumeRm(vars["name"]); err != nil {
|
|
return err
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
return nil
|
|
}
|