podman

Форк
0
55 строк · 1.6 Кб
1
package docker
2

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

10
// InspectContainer returns information about a container by its ID.
11
//
12
// Deprecated: Use InspectContainerWithOptions instead.
13
func (c *Client) InspectContainer(id string) (*Container, error) {
14
	return c.InspectContainerWithOptions(InspectContainerOptions{ID: id})
15
}
16

17
// InspectContainerWithContext returns information about a container by its ID.
18
// The context object can be used to cancel the inspect request.
19
//
20
// Deprecated: Use InspectContainerWithOptions instead.
21
func (c *Client) InspectContainerWithContext(id string, ctx context.Context) (*Container, error) {
22
	return c.InspectContainerWithOptions(InspectContainerOptions{ID: id, Context: ctx})
23
}
24

25
// InspectContainerWithOptions returns information about a container by its ID.
26
//
27
// See https://goo.gl/FaI5JT for more details.
28
func (c *Client) InspectContainerWithOptions(opts InspectContainerOptions) (*Container, error) {
29
	path := "/containers/" + opts.ID + "/json?" + queryString(opts)
30
	resp, err := c.do(http.MethodGet, path, doOptions{
31
		context: opts.Context,
32
	})
33
	if err != nil {
34
		var e *Error
35
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
36
			return nil, &NoSuchContainer{ID: opts.ID}
37
		}
38
		return nil, err
39
	}
40
	defer resp.Body.Close()
41
	var container Container
42
	if err := json.NewDecoder(resp.Body).Decode(&container); err != nil {
43
		return nil, err
44
	}
45
	return &container, nil
46
}
47

48
// InspectContainerOptions specifies parameters for InspectContainerWithOptions.
49
//
50
// See https://goo.gl/FaI5JT for more details.
51
type InspectContainerOptions struct {
52
	Context context.Context
53
	ID      string `qs:"-"`
54
	Size    bool
55
}
56

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

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

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

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