system.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package system // import "github.com/docker/docker/api/server/router/system"
  2. import (
  3. "github.com/docker/docker/api/server/router"
  4. "github.com/docker/docker/api/types/system"
  5. buildkit "github.com/docker/docker/builder/builder-next"
  6. "resenje.org/singleflight"
  7. )
  8. // systemRouter provides information about the Docker system overall.
  9. // It gathers information about host, daemon and container events.
  10. type systemRouter struct {
  11. backend Backend
  12. cluster ClusterBackend
  13. routes []router.Route
  14. builder *buildkit.Builder
  15. features func() map[string]bool
  16. // collectSystemInfo is a single-flight for the /info endpoint,
  17. // unique per API version (as different API versions may return
  18. // a different API response).
  19. collectSystemInfo singleflight.Group[string, *system.Info]
  20. }
  21. // NewRouter initializes a new system router
  22. func NewRouter(b Backend, c ClusterBackend, builder *buildkit.Builder, features func() map[string]bool) router.Router {
  23. r := &systemRouter{
  24. backend: b,
  25. cluster: c,
  26. builder: builder,
  27. features: features,
  28. }
  29. r.routes = []router.Route{
  30. router.NewOptionsRoute("/{anyroute:.*}", optionsHandler),
  31. router.NewGetRoute("/_ping", r.pingHandler),
  32. router.NewHeadRoute("/_ping", r.pingHandler),
  33. router.NewGetRoute("/events", r.getEvents),
  34. router.NewGetRoute("/info", r.getInfo),
  35. router.NewGetRoute("/version", r.getVersion),
  36. router.NewGetRoute("/system/df", r.getDiskUsage),
  37. router.NewPostRoute("/auth", r.postAuth),
  38. }
  39. return r
  40. }
  41. // Routes returns all the API routes dedicated to the docker system
  42. func (s *systemRouter) Routes() []router.Route {
  43. return s.routes
  44. }