podman
55 строк · 1.6 Кб
1package docker
2
3import (
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.
13func (c *Client) InspectContainer(id string) (*Container, error) {
14return 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.
21func (c *Client) InspectContainerWithContext(id string, ctx context.Context) (*Container, error) {
22return 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.
28func (c *Client) InspectContainerWithOptions(opts InspectContainerOptions) (*Container, error) {
29path := "/containers/" + opts.ID + "/json?" + queryString(opts)
30resp, err := c.do(http.MethodGet, path, doOptions{
31context: opts.Context,
32})
33if err != nil {
34var e *Error
35if errors.As(err, &e) && e.Status == http.StatusNotFound {
36return nil, &NoSuchContainer{ID: opts.ID}
37}
38return nil, err
39}
40defer resp.Body.Close()
41var container Container
42if err := json.NewDecoder(resp.Body).Decode(&container); err != nil {
43return nil, err
44}
45return &container, nil
46}
47
48// InspectContainerOptions specifies parameters for InspectContainerWithOptions.
49//
50// See https://goo.gl/FaI5JT for more details.
51type InspectContainerOptions struct {
52Context context.Context
53ID string `qs:"-"`
54Size bool
55}
56