inspect.go 821 B

123456789101112131415161718192021222324252627282930313233
  1. package local
  2. import (
  3. "net/http"
  4. "github.com/docker/docker/api/server/httputils"
  5. "golang.org/x/net/context"
  6. )
  7. // getContainersByName inspects containers configuration and serializes it as json.
  8. func (s *router) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
  9. displaySize := httputils.BoolValue(r, "size")
  10. var json interface{}
  11. var err error
  12. version := httputils.VersionFromContext(ctx)
  13. switch {
  14. case version.LessThan("1.20"):
  15. json, err = s.daemon.ContainerInspectPre120(vars["name"])
  16. case version.Equal("1.20"):
  17. json, err = s.daemon.ContainerInspect120(vars["name"])
  18. default:
  19. json, err = s.daemon.ContainerInspect(vars["name"], displaySize)
  20. }
  21. if err != nil {
  22. return err
  23. }
  24. return httputils.WriteJSON(w, http.StatusOK, json)
  25. }