podman

Форк
0
46 строк · 1.1 Кб
1
package docker
2

3
import (
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.
13
type KillContainerOptions struct {
14
	// The ID of the container.
15
	ID string `qs:"-"`
16

17
	// The signal to send to the container. When omitted, Docker server
18
	// will assume SIGKILL.
19
	Signal  Signal
20
	Context context.Context
21
}
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.
27
func (c *Client) KillContainer(opts KillContainerOptions) error {
28
	path := "/containers/" + opts.ID + "/kill" + "?" + queryString(opts)
29
	resp, err := c.do(http.MethodPost, path, doOptions{context: opts.Context})
30
	if err != nil {
31
		var e *Error
32
		if !errors.As(err, &e) {
33
			return err
34
		}
35
		switch e.Status {
36
		case http.StatusNotFound:
37
			return &NoSuchContainer{ID: opts.ID}
38
		case http.StatusConflict:
39
			return &ContainerNotRunning{ID: opts.ID}
40
		default:
41
			return err
42
		}
43
	}
44
	resp.Body.Close()
45
	return nil
46
}
47

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.