Files
moby/client/container_update.go
Sebastiaan van Stijn b20c3db932 client: request: use consistent order or arguments
Make `body` the last argument, so that requests can be inlined on call-sites.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-29 14:14:26 +02:00

42 lines
1.2 KiB
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/container"
)
// ContainerUpdateOptions holds options for [Client.ContainerUpdate].
type ContainerUpdateOptions struct {
Resources *container.Resources
RestartPolicy *container.RestartPolicy
}
// ContainerUpdateResult is the result from updating a container.
type ContainerUpdateResult struct {
// Warnings encountered when updating the container.
Warnings []string
}
// ContainerUpdate updates the resources of a container.
func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, options ContainerUpdateOptions) (ContainerUpdateResult, error) {
containerID, err := trimID("container", containerID)
if err != nil {
return ContainerUpdateResult{}, err
}
resp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, nil, container.UpdateConfig{
Resources: valueOrZero(options.Resources),
RestartPolicy: valueOrZero(options.RestartPolicy),
})
defer ensureReaderClosed(resp)
if err != nil {
return ContainerUpdateResult{}, err
}
var response container.UpdateResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return ContainerUpdateResult{Warnings: response.Warnings}, err
}