system.go 1.7 KB

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