inspect.go 775 B

1234567891011121314151617181920212223242526272829303132333435
  1. package server
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/docker/docker/context"
  6. )
  7. // getContainersByName inspects containers configuration and serializes it as json.
  8. func (s *Server) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
  9. if vars == nil {
  10. return fmt.Errorf("Missing parameter")
  11. }
  12. var json interface{}
  13. var err error
  14. version := ctx.Version()
  15. switch {
  16. case version.LessThan("1.20"):
  17. json, err = s.daemon.ContainerInspectPre120(ctx, vars["name"])
  18. case version.Equal("1.20"):
  19. json, err = s.daemon.ContainerInspect120(ctx, vars["name"])
  20. default:
  21. json, err = s.daemon.ContainerInspect(ctx, vars["name"])
  22. }
  23. if err != nil {
  24. return err
  25. }
  26. return writeJSON(w, http.StatusOK, json)
  27. }