podman

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

3
import (
4
	"context"
5
	"encoding/json"
6
	"errors"
7
	"net/http"
8
)
9

10
// WaitContainer blocks until the given container stops, return the exit code
11
// of the container status.
12
//
13
// See https://goo.gl/4AGweZ for more details.
14
func (c *Client) WaitContainer(id string) (int, error) {
15
	return c.waitContainer(id, doOptions{})
16
}
17

18
// WaitContainerWithContext blocks until the given container stops, return the exit code
19
// of the container status. The context object can be used to cancel the
20
// inspect request.
21
//
22
// See https://goo.gl/4AGweZ for more details.
23
func (c *Client) WaitContainerWithContext(id string, ctx context.Context) (int, error) {
24
	return c.waitContainer(id, doOptions{context: ctx})
25
}
26

27
func (c *Client) waitContainer(id string, opts doOptions) (int, error) {
28
	resp, err := c.do(http.MethodPost, "/containers/"+id+"/wait", opts)
29
	if err != nil {
30
		var e *Error
31
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
32
			return 0, &NoSuchContainer{ID: id}
33
		}
34
		return 0, err
35
	}
36
	defer resp.Body.Close()
37
	var r struct{ StatusCode int }
38
	if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
39
		return 0, err
40
	}
41
	return r.StatusCode, nil
42
}
43

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

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

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

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