mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Lowercase http method functions.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
0b0431a856
commit
d9a62c5f2b
30 changed files with 63 additions and 57 deletions
|
@ -35,7 +35,7 @@ func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.POST("/commit", query, config, nil)
|
resp, err := cli.post("/commit", query, config, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (cli *Client) ContainerCreate(config *runconfig.ContainerConfigWrapper, con
|
||||||
query.Set("name", containerName)
|
query.Set("name", containerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
serverResp, err := cli.POST("/containers/create", query, config, nil)
|
serverResp, err := cli.post("/containers/create", query, config, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if serverResp != nil && serverResp.statusCode == 404 && strings.Contains(err.Error(), config.Image) {
|
if serverResp != nil && serverResp.statusCode == 404 && strings.Contains(err.Error(), config.Image) {
|
||||||
return response, imageNotFoundError{config.Image}
|
return response, imageNotFoundError{config.Image}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
// ContainerInspect returns the all the container information.
|
// ContainerInspect returns the all the container information.
|
||||||
func (cli *Client) ContainerInspect(containerID string) (types.ContainerJSON, error) {
|
func (cli *Client) ContainerInspect(containerID string) (types.ContainerJSON, error) {
|
||||||
serverResp, err := cli.GET("/containers/"+containerID+"/json", nil, nil)
|
serverResp, err := cli.get("/containers/"+containerID+"/json", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ContainerJSON{}, err
|
return types.ContainerJSON{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (cli *Client) ContainerList(options types.ContainerListOptions) ([]types.Co
|
||||||
query.Set("filters", filterJSON)
|
query.Set("filters", filterJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.GET("/containers/json", query, nil)
|
resp, err := cli.get("/containers/json", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (cli *Client) ContainerRemove(options types.ContainerRemoveOptions) error {
|
||||||
query.Set("force", "1")
|
query.Set("force", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.DELETE("/containers/"+options.ContainerID, query, nil)
|
resp, err := cli.delete("/containers/"+options.ContainerID, query, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import "net/url"
|
||||||
func (cli *Client) ContainerRename(containerID, newContainerName string) error {
|
func (cli *Client) ContainerRename(containerID, newContainerName string) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("name", newContainerName)
|
query.Set("name", newContainerName)
|
||||||
resp, err := cli.POST("/containers/"+containerID+"/rename", query, nil, nil)
|
resp, err := cli.post("/containers/"+containerID+"/rename", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func (cli *Client) ContainerRestart(containerID string, timeout int) error {
|
func (cli *Client) ContainerRestart(containerID string, timeout int) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("t", strconv.Itoa(timeout))
|
query.Set("t", strconv.Itoa(timeout))
|
||||||
resp, err := cli.POST("/containers"+containerID+"/restart", query, nil, nil)
|
resp, err := cli.post("/containers/"+containerID+"/restart", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func (cli *Client) ContainerStop(containerID string, timeout int) error {
|
func (cli *Client) ContainerStop(containerID string, timeout int) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("t", strconv.Itoa(timeout))
|
query.Set("t", strconv.Itoa(timeout))
|
||||||
resp, err := cli.POST("/containers/"+containerID+"/stop", query, nil, nil)
|
resp, err := cli.post("/containers/"+containerID+"/stop", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package lib
|
||||||
|
|
||||||
// ContainerUnpause resumes the process execution within a container
|
// ContainerUnpause resumes the process execution within a container
|
||||||
func (cli *Client) ContainerUnpause(containerID string) error {
|
func (cli *Client) ContainerUnpause(containerID string) error {
|
||||||
resp, err := cli.POST("/containers/"+containerID+"/unpause", nil, nil, nil)
|
resp, err := cli.post("/containers/"+containerID+"/unpause", nil, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (cli *Client) ContainerStatPath(containerID, path string) (types.ContainerP
|
||||||
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
|
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
|
||||||
|
|
||||||
urlStr := fmt.Sprintf("/containers/%s/archive", containerID)
|
urlStr := fmt.Sprintf("/containers/%s/archive", containerID)
|
||||||
response, err := cli.HEAD(urlStr, query, nil)
|
response, err := cli.head(urlStr, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ContainerPathStat{}, err
|
return types.ContainerPathStat{}, err
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (cli *Client) CopyToContainer(options types.CopyToContainerOptions) error {
|
||||||
|
|
||||||
path := fmt.Sprintf("/containers/%s/archive", options.ContainerID)
|
path := fmt.Sprintf("/containers/%s/archive", options.ContainerID)
|
||||||
|
|
||||||
response, err := cli.PUT(path, query, options.Content, nil)
|
response, err := cli.putRaw(path, query, options.Content, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func (cli *Client) CopyFromContainer(containerID, srcPath string) (io.ReadCloser
|
||||||
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
|
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
|
||||||
|
|
||||||
apiPath := fmt.Sprintf("/containers/%s/archive", containerID)
|
apiPath := fmt.Sprintf("/containers/%s/archive", containerID)
|
||||||
response, err := cli.GET(apiPath, query, nil)
|
response, err := cli.get(apiPath, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, types.ContainerPathStat{}, err
|
return nil, types.ContainerPathStat{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func (cli *Client) ContainerDiff(containerID string) ([]types.ContainerChange, error) {
|
func (cli *Client) ContainerDiff(containerID string) ([]types.ContainerChange, error) {
|
||||||
var changes []types.ContainerChange
|
var changes []types.ContainerChange
|
||||||
|
|
||||||
serverResp, err := cli.GET("/containers/"+containerID+"/changes", url.Values{}, nil)
|
serverResp, err := cli.get("/containers/"+containerID+"/changes", url.Values{}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return changes, err
|
return changes, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (cli *Client) Events(options types.EventsOptions) (io.ReadCloser, error) {
|
||||||
query.Set("filters", filterJSON)
|
query.Set("filters", filterJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
serverResponse, err := cli.GET("/events", query, nil)
|
serverResponse, err := cli.get("/events", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
// and returns them as a io.ReadCloser. It's up to the caller
|
// and returns them as a io.ReadCloser. It's up to the caller
|
||||||
// to close the stream.
|
// to close the stream.
|
||||||
func (cli *Client) ContainerExport(containerID string) (io.ReadCloser, error) {
|
func (cli *Client) ContainerExport(containerID string) (io.ReadCloser, error) {
|
||||||
serverResp, err := cli.GET("/containers/"+containerID+"/export", url.Values{}, nil)
|
serverResp, err := cli.get("/containers/"+containerID+"/export", url.Values{}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// ImageHistory returns the changes in an image in history format.
|
// ImageHistory returns the changes in an image in history format.
|
||||||
func (cli *Client) ImageHistory(imageID string) ([]types.ImageHistory, error) {
|
func (cli *Client) ImageHistory(imageID string) ([]types.ImageHistory, error) {
|
||||||
var history []types.ImageHistory
|
var history []types.ImageHistory
|
||||||
serverResp, err := cli.GET("/images/"+imageID+"/history", url.Values{}, nil)
|
serverResp, err := cli.get("/images/"+imageID+"/history", url.Values{}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return history, err
|
return history, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (cli *Client) ImageBuild(options types.ImageBuildOptions) (types.ImageBuild
|
||||||
headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
|
headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
|
||||||
headers.Set("Content-Type", "application/tar")
|
headers.Set("Content-Type", "application/tar")
|
||||||
|
|
||||||
serverResp, err := cli.POSTRaw("/build", query, options.Context, headers)
|
serverResp, err := cli.postRaw("/build", query, options.Context, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ImageBuildResponse{}, err
|
return types.ImageBuildResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (cli *Client) ImageCreate(options types.ImageCreateOptions) (io.ReadCloser,
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", options.Tag)
|
||||||
|
|
||||||
headers := map[string][]string{"X-Registry-Auth": {options.RegistryAuth}}
|
headers := map[string][]string{"X-Registry-Auth": {options.RegistryAuth}}
|
||||||
resp, err := cli.POST("/images/create", query, nil, headers)
|
resp, err := cli.post("/images/create", query, nil, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (cli *Client) ImageImport(options types.ImageImportOptions) (io.ReadCloser,
|
||||||
query.Add("changes", change)
|
query.Add("changes", change)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.POSTRaw("/images/create", query, options.Source, nil)
|
resp, err := cli.postRaw("/images/create", query, options.Source, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
func (cli *Client) ImageList(options types.ImageListOptions) ([]types.Image, error) {
|
func (cli *Client) ImageList(options types.ImageListOptions) ([]types.Image, error) {
|
||||||
var images []types.Image
|
var images []types.Image
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|
||||||
if options.Filters.Len() > 0 {
|
if options.Filters.Len() > 0 {
|
||||||
filterJSON, err := filters.ToParam(options.Filters)
|
filterJSON, err := filters.ToParam(options.Filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,7 +28,7 @@ func (cli *Client) ImageList(options types.ImageListOptions) ([]types.Image, err
|
||||||
query.Set("all", "1")
|
query.Set("all", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
serverResp, err := cli.GET("/images/json?", query, nil)
|
serverResp, err := cli.get("/images/json", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return images, err
|
return images, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
// It's up to the caller to close the io.ReadCloser returned by
|
// It's up to the caller to close the io.ReadCloser returned by
|
||||||
// this function.
|
// this function.
|
||||||
func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
||||||
resp, err := cli.POSTRaw("/images/load", url.Values{}, input, nil)
|
resp, err := cli.postRaw("/images/load", url.Values{}, input, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (cli *Client) ImageRemove(options types.ImageRemoveOptions) ([]types.ImageD
|
||||||
query.Set("noprune", "1")
|
query.Set("noprune", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.DELETE("/images/"+options.ImageID, query, nil)
|
resp, err := cli.delete("/images/"+options.ImageID, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ func (cli *Client) ImageSave(imageIDs []string) (io.ReadCloser, error) {
|
||||||
"names": imageIDs,
|
"names": imageIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.GET("/images/get", query, nil)
|
resp, err := cli.get("/images/get", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (cli *Client) ImageTag(options types.ImageTagOptions) error {
|
||||||
query.Set("force", "1")
|
query.Set("force", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.POST("/images/"+options.ImageID+"/tag", query, nil, nil)
|
resp, err := cli.post("/images/"+options.ImageID+"/tag", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// Info returns information about the docker server.
|
// Info returns information about the docker server.
|
||||||
func (cli *Client) Info() (types.Info, error) {
|
func (cli *Client) Info() (types.Info, error) {
|
||||||
var info types.Info
|
var info types.Info
|
||||||
serverResp, err := cli.GET("/info", url.Values{}, nil)
|
serverResp, err := cli.get("/info", url.Values{}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ func (cli *Client) ContainerKill(containerID, signal string) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("signal", signal)
|
query.Set("signal", signal)
|
||||||
|
|
||||||
resp, err := cli.POST("/containers/"+containerID+"/kill", query, nil, nil)
|
resp, err := cli.post("/containers/"+containerID+"/kill", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// RegistryLogin authenticates the docker server with a given docker registry.
|
// RegistryLogin authenticates the docker server with a given docker registry.
|
||||||
// It returns UnauthorizerError when the authentication fails.
|
// It returns UnauthorizerError when the authentication fails.
|
||||||
func (cli *Client) RegistryLogin(auth cliconfig.AuthConfig) (types.AuthResponse, error) {
|
func (cli *Client) RegistryLogin(auth cliconfig.AuthConfig) (types.AuthResponse, error) {
|
||||||
resp, err := cli.POST("/auth", url.Values{}, auth, nil)
|
resp, err := cli.post("/auth", url.Values{}, auth, nil)
|
||||||
|
|
||||||
if resp != nil && resp.statusCode == http.StatusUnauthorized {
|
if resp != nil && resp.statusCode == http.StatusUnauthorized {
|
||||||
return types.AuthResponse{}, unauthorizedError{err}
|
return types.AuthResponse{}, unauthorizedError{err}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (cli *Client) ContainerLogs(options types.ContainerLogsOptions) (io.ReadClo
|
||||||
}
|
}
|
||||||
query.Set("tail", options.Tail)
|
query.Set("tail", options.Tail)
|
||||||
|
|
||||||
resp, err := cli.GET("/containers/"+options.ContainerID+"/logs", query, nil)
|
resp, err := cli.get("/containers/"+options.ContainerID+"/logs", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
// NetworkCreate creates a new network in the docker host.
|
// NetworkCreate creates a new network in the docker host.
|
||||||
func (cli *Client) NetworkCreate(options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
func (cli *Client) NetworkCreate(options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
||||||
var response types.NetworkCreateResponse
|
var response types.NetworkCreateResponse
|
||||||
serverResp, err := cli.POST("/networks/create", nil, options, nil)
|
serverResp, err := cli.post("/networks/create", nil, options, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func (cli *Client) NetworkCreate(options types.NetworkCreate) (types.NetworkCrea
|
||||||
|
|
||||||
// NetworkRemove removes an existent network from the docker host.
|
// NetworkRemove removes an existent network from the docker host.
|
||||||
func (cli *Client) NetworkRemove(networkID string) error {
|
func (cli *Client) NetworkRemove(networkID string) error {
|
||||||
resp, err := cli.DELETE("/networks/"+networkID, nil, nil)
|
resp, err := cli.delete("/networks/"+networkID, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func (cli *Client) NetworkRemove(networkID string) error {
|
||||||
// NetworkConnect connects a container to an existent network in the docker host.
|
// NetworkConnect connects a container to an existent network in the docker host.
|
||||||
func (cli *Client) NetworkConnect(networkID, containerID string) error {
|
func (cli *Client) NetworkConnect(networkID, containerID string) error {
|
||||||
nc := types.NetworkConnect{containerID}
|
nc := types.NetworkConnect{containerID}
|
||||||
resp, err := cli.POST("/networks/"+networkID+"/connect", nil, nc, nil)
|
resp, err := cli.post("/networks/"+networkID+"/connect", nil, nc, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ func (cli *Client) NetworkConnect(networkID, containerID string) error {
|
||||||
// NetworkDisconnect disconnects a container from an existent network in the docker host.
|
// NetworkDisconnect disconnects a container from an existent network in the docker host.
|
||||||
func (cli *Client) NetworkDisconnect(networkID, containerID string) error {
|
func (cli *Client) NetworkDisconnect(networkID, containerID string) error {
|
||||||
nc := types.NetworkConnect{containerID}
|
nc := types.NetworkConnect{containerID}
|
||||||
resp, err := cli.POST("/networks/"+networkID+"/disconnect", nil, nc, nil)
|
resp, err := cli.post("/networks/"+networkID+"/disconnect", nil, nc, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (cli *Client) NetworkDisconnect(networkID, containerID string) error {
|
||||||
// NetworkList returns the list of networks configured in the docker host.
|
// NetworkList returns the list of networks configured in the docker host.
|
||||||
func (cli *Client) NetworkList() ([]types.NetworkResource, error) {
|
func (cli *Client) NetworkList() ([]types.NetworkResource, error) {
|
||||||
var networkResources []types.NetworkResource
|
var networkResources []types.NetworkResource
|
||||||
resp, err := cli.GET("/networks", nil, nil)
|
resp, err := cli.get("/networks", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return networkResources, err
|
return networkResources, err
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func (cli *Client) NetworkList() ([]types.NetworkResource, error) {
|
||||||
// NetworkInspect returns the information for a specific network configured in the docker host.
|
// NetworkInspect returns the information for a specific network configured in the docker host.
|
||||||
func (cli *Client) NetworkInspect(networkID string) (types.NetworkResource, error) {
|
func (cli *Client) NetworkInspect(networkID string) (types.NetworkResource, error) {
|
||||||
var networkResource types.NetworkResource
|
var networkResource types.NetworkResource
|
||||||
resp, err := cli.GET("/networks/"+networkID, nil, nil)
|
resp, err := cli.get("/networks/"+networkID, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return networkResource, err
|
return networkResource, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,44 +13,49 @@ import (
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServerResponse is a wrapper for http API responses.
|
// serverResponse is a wrapper for http API responses.
|
||||||
type ServerResponse struct {
|
type serverResponse struct {
|
||||||
body io.ReadCloser
|
body io.ReadCloser
|
||||||
header http.Header
|
header http.Header
|
||||||
statusCode int
|
statusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
// HEAD sends an http request to the docker API using the method HEAD.
|
// head sends an http request to the docker API using the method HEAD.
|
||||||
func (cli *Client) HEAD(path string, query url.Values, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) head(path string, query url.Values, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendRequest("HEAD", path, query, nil, headers)
|
return cli.sendRequest("HEAD", path, query, nil, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET sends an http request to the docker API using the method GET.
|
// get sends an http request to the docker API using the method GET.
|
||||||
func (cli *Client) GET(path string, query url.Values, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) get(path string, query url.Values, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendRequest("GET", path, query, nil, headers)
|
return cli.sendRequest("GET", path, query, nil, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST sends an http request to the docker API using the method POST.
|
// post sends an http request to the docker API using the method POST.
|
||||||
func (cli *Client) POST(path string, query url.Values, body interface{}, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) post(path string, query url.Values, body interface{}, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendRequest("POST", path, query, body, headers)
|
return cli.sendRequest("POST", path, query, body, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// POSTRaw sends the raw input to the docker API using the method POST.
|
// postRaw sends the raw input to the docker API using the method POST.
|
||||||
func (cli *Client) POSTRaw(path string, query url.Values, body io.Reader, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) postRaw(path string, query url.Values, body io.Reader, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendClientRequest("POST", path, query, body, headers)
|
return cli.sendClientRequest("POST", path, query, body, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT sends an http request to the docker API using the method PUT.
|
// put sends an http request to the docker API using the method PUT.
|
||||||
func (cli *Client) PUT(path string, query url.Values, body interface{}, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) put(path string, query url.Values, body interface{}, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendRequest("PUT", path, query, body, headers)
|
return cli.sendRequest("PUT", path, query, body, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE sends an http request to the docker API using the method DELETE.
|
// putRaw sends the raw input to the docker API using the method PUT.
|
||||||
func (cli *Client) DELETE(path string, query url.Values, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) putRaw(path string, query url.Values, body io.Reader, headers map[string][]string) (*serverResponse, error) {
|
||||||
|
return cli.sendClientRequest("PUT", path, query, body, headers)
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete sends an http request to the docker API using the method DELETE.
|
||||||
|
func (cli *Client) delete(path string, query url.Values, headers map[string][]string) (*serverResponse, error) {
|
||||||
return cli.sendRequest("DELETE", path, query, nil, headers)
|
return cli.sendRequest("DELETE", path, query, nil, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) sendRequest(method, path string, query url.Values, body interface{}, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) sendRequest(method, path string, query url.Values, body interface{}, headers map[string][]string) (*serverResponse, error) {
|
||||||
params, err := encodeData(body)
|
params, err := encodeData(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -66,8 +71,8 @@ func (cli *Client) sendRequest(method, path string, query url.Values, body inter
|
||||||
return cli.sendClientRequest(method, path, query, params, headers)
|
return cli.sendClientRequest(method, path, query, params, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) sendClientRequest(method, path string, query url.Values, in io.Reader, headers map[string][]string) (*ServerResponse, error) {
|
func (cli *Client) sendClientRequest(method, path string, query url.Values, in io.Reader, headers map[string][]string) (*serverResponse, error) {
|
||||||
serverResp := &ServerResponse{
|
serverResp := &serverResponse{
|
||||||
body: nil,
|
body: nil,
|
||||||
statusCode: -1,
|
statusCode: -1,
|
||||||
}
|
}
|
||||||
|
@ -148,7 +153,7 @@ func encodeData(data interface{}) (*bytes.Buffer, error) {
|
||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureReaderClosed(response *ServerResponse) {
|
func ensureReaderClosed(response *serverResponse) {
|
||||||
if response != nil && response.body != nil {
|
if response != nil && response.body != nil {
|
||||||
response.body.Close()
|
response.body.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (cli *Client) SystemVersion() (types.VersionResponse, error) {
|
||||||
Experimental: utils.ExperimentalBuild(),
|
Experimental: utils.ExperimentalBuild(),
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.GET("/version", nil, nil)
|
resp, err := cli.get("/version", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.VersionResponse{Client: client}, err
|
return types.VersionResponse{Client: client}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (cli *Client) VolumeList(filter filters.Args) (types.VolumesListResponse, e
|
||||||
}
|
}
|
||||||
query.Set("filters", filterJSON)
|
query.Set("filters", filterJSON)
|
||||||
}
|
}
|
||||||
resp, err := cli.GET("/volumes", query, nil)
|
resp, err := cli.get("/volumes", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumes, err
|
return volumes, err
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func (cli *Client) VolumeList(filter filters.Args) (types.VolumesListResponse, e
|
||||||
// VolumeInspect returns the information about a specific volume in the docker host.
|
// VolumeInspect returns the information about a specific volume in the docker host.
|
||||||
func (cli *Client) VolumeInspect(volumeID string) (types.Volume, error) {
|
func (cli *Client) VolumeInspect(volumeID string) (types.Volume, error) {
|
||||||
var volume types.Volume
|
var volume types.Volume
|
||||||
resp, err := cli.GET("/volumes"+volumeID, nil, nil)
|
resp, err := cli.get("/volumes/"+volumeID, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volume, err
|
return volume, err
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (cli *Client) VolumeInspect(volumeID string) (types.Volume, error) {
|
||||||
// VolumeCreate creates a volume in the docker host.
|
// VolumeCreate creates a volume in the docker host.
|
||||||
func (cli *Client) VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error) {
|
func (cli *Client) VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error) {
|
||||||
var volume types.Volume
|
var volume types.Volume
|
||||||
resp, err := cli.POST("/volumes/create", nil, options, nil)
|
resp, err := cli.post("/volumes/create", nil, options, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volume, err
|
return volume, err
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func (cli *Client) VolumeCreate(options types.VolumeCreateRequest) (types.Volume
|
||||||
|
|
||||||
// VolumeRemove removes a volume from the docker host.
|
// VolumeRemove removes a volume from the docker host.
|
||||||
func (cli *Client) VolumeRemove(volumeID string) error {
|
func (cli *Client) VolumeRemove(volumeID string) error {
|
||||||
resp, err := cli.DELETE("/volumes"+volumeID, nil, nil)
|
resp, err := cli.delete("/volumes/"+volumeID, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue