mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: add option and output structs for various container methods
Add option- and output structs for; - Client.ContainerKill - Client.ContainerPause - Client.ContainerRemove - Client.ContainerResize - Client.ContainerRestart - Client.ContainerStart - Client.ContainerStop - Client.ContainerUnpause Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -6,13 +6,36 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ContainerRestartOptions holds options for [Client.ContainerRestart].
|
||||
type ContainerRestartOptions struct {
|
||||
// Signal (optional) is the signal to send to the container to (gracefully)
|
||||
// stop it before forcibly terminating the container with SIGKILL after the
|
||||
// timeout expires. If no value is set, the default (SIGTERM) is used.
|
||||
Signal string `json:",omitempty"`
|
||||
|
||||
// Timeout (optional) is the timeout (in seconds) to wait for the container
|
||||
// to stop gracefully before forcibly terminating it with SIGKILL.
|
||||
//
|
||||
// - Use nil to use the default timeout (10 seconds).
|
||||
// - Use '-1' to wait indefinitely.
|
||||
// - Use '0' to not wait for the container to exit gracefully, and
|
||||
// immediately proceeds to forcibly terminating the container.
|
||||
// - Other positive values are used as timeout (in seconds).
|
||||
Timeout *int `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ContainerRestartResult holds the result of [Client.ContainerRestart],
|
||||
type ContainerRestartResult struct {
|
||||
// Add future fields here.
|
||||
}
|
||||
|
||||
// ContainerRestart stops, and starts a container again.
|
||||
// It makes the daemon wait for the container to be up again for
|
||||
// a specific amount of time, given the timeout.
|
||||
func (cli *Client) ContainerRestart(ctx context.Context, containerID string, options ContainerStopOptions) error {
|
||||
func (cli *Client) ContainerRestart(ctx context.Context, containerID string, options ContainerRestartOptions) (ContainerRestartResult, error) {
|
||||
containerID, err := trimID("container", containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
return ContainerRestartResult{}, err
|
||||
}
|
||||
|
||||
query := url.Values{}
|
||||
@@ -24,5 +47,8 @@ func (cli *Client) ContainerRestart(ctx context.Context, containerID string, opt
|
||||
}
|
||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
return err
|
||||
if err != nil {
|
||||
return ContainerRestartResult{}, err
|
||||
}
|
||||
return ContainerRestartResult{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user