podman
46 строк · 1.1 Кб
1package docker2
3import (4"context"5"errors"6"net/http"7)
8
9// KillContainerOptions represents the set of options that can be used in a
10// call to KillContainer.
11//
12// See https://goo.gl/JnTxXZ for more details.
13type KillContainerOptions struct {14// The ID of the container.15ID string `qs:"-"`16
17// The signal to send to the container. When omitted, Docker server18// will assume SIGKILL.19Signal Signal
20Context context.Context21}
22
23// KillContainer sends a signal to a container, returning an error in case of
24// failure.
25//
26// See https://goo.gl/JnTxXZ for more details.
27func (c *Client) KillContainer(opts KillContainerOptions) error {28path := "/containers/" + opts.ID + "/kill" + "?" + queryString(opts)29resp, err := c.do(http.MethodPost, path, doOptions{context: opts.Context})30if err != nil {31var e *Error32if !errors.As(err, &e) {33return err34}35switch e.Status {36case http.StatusNotFound:37return &NoSuchContainer{ID: opts.ID}38case http.StatusConflict:39return &ContainerNotRunning{ID: opts.ID}40default:41return err42}43}44resp.Body.Close()45return nil46}
47