config_inspect.go 899 B

123456789101112131415161718192021222324252627282930313233343536
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "io"
  7. "github.com/docker/docker/api/types/swarm"
  8. )
  9. // ConfigInspectWithRaw returns the config information with raw data
  10. func (cli *Client) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) {
  11. if id == "" {
  12. return swarm.Config{}, nil, objectNotFoundError{object: "config", id: id}
  13. }
  14. if err := cli.NewVersionError(ctx, "1.30", "config inspect"); err != nil {
  15. return swarm.Config{}, nil, err
  16. }
  17. resp, err := cli.get(ctx, "/configs/"+id, nil, nil)
  18. defer ensureReaderClosed(resp)
  19. if err != nil {
  20. return swarm.Config{}, nil, err
  21. }
  22. body, err := io.ReadAll(resp.body)
  23. if err != nil {
  24. return swarm.Config{}, nil, err
  25. }
  26. var config swarm.Config
  27. rdr := bytes.NewReader(body)
  28. err = json.NewDecoder(rdr).Decode(&config)
  29. return config, body, err
  30. }