github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/api/server/router/system/system.go (about)

     1  package system // import "github.com/Prakhar-Agarwal-byte/moby/api/server/router/system"
     2  
     3  import (
     4  	"github.com/Prakhar-Agarwal-byte/moby/api/server/router"
     5  	"github.com/Prakhar-Agarwal-byte/moby/api/types/system"
     6  	buildkit "github.com/Prakhar-Agarwal-byte/moby/builder/builder-next"
     7  	"resenje.org/singleflight"
     8  )
     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  
    19  	// collectSystemInfo is a single-flight for the /info endpoint,
    20  	// unique per API version (as different API versions may return
    21  	// a different API response).
    22  	collectSystemInfo singleflight.Group[string, *system.Info]
    23  }
    24  
    25  // NewRouter initializes a new system router
    26  func NewRouter(b Backend, c ClusterBackend, builder *buildkit.Builder, features func() map[string]bool) router.Router {
    27  	r := &systemRouter{
    28  		backend:  b,
    29  		cluster:  c,
    30  		builder:  builder,
    31  		features: features,
    32  	}
    33  
    34  	r.routes = []router.Route{
    35  		router.NewOptionsRoute("/{anyroute:.*}", optionsHandler),
    36  		router.NewGetRoute("/_ping", r.pingHandler),
    37  		router.NewHeadRoute("/_ping", r.pingHandler),
    38  		router.NewGetRoute("/events", r.getEvents),
    39  		router.NewGetRoute("/info", r.getInfo),
    40  		router.NewGetRoute("/version", r.getVersion),
    41  		router.NewGetRoute("/system/df", r.getDiskUsage),
    42  		router.NewPostRoute("/auth", r.postAuth),
    43  	}
    44  
    45  	return r
    46  }
    47  
    48  // Routes returns all the API routes dedicated to the docker system
    49  func (s *systemRouter) Routes() []router.Route {
    50  	return s.routes
    51  }