Merge pull request #50996 from thaJeztah/server_cleanups

daemon/server: minor refactor and cleanup
This commit is contained in:
Sebastiaan van Stijn
2025-09-19 10:18:09 +02:00
committed by GitHub
2 changed files with 5 additions and 3 deletions

View File

@@ -37,7 +37,7 @@ func (l localRoute) Path() string {
// NewRoute initializes a new local route for the router.
func NewRoute(method, path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
var r Route = localRoute{method, path, handler}
var r Route = localRoute{method: method, path: path, handler: handler}
for _, o := range opts {
r = o(r)
}

View File

@@ -33,7 +33,9 @@ func (s *Server) UseMiddleware(m middleware.Middleware) {
s.middlewares = append(s.middlewares, m)
}
func (s *Server) makeHTTPHandler(handler httputils.APIFunc, operation string) http.HandlerFunc {
func (s *Server) makeHTTPHandler(r router.Route) http.HandlerFunc {
handler := r.Handler()
operation := r.Method() + " " + r.Path()
return otelhttp.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Define the context that we'll pass around to share info
// like the docker-request-id.
@@ -91,7 +93,7 @@ func (s *Server) CreateMux(ctx context.Context, routers ...router.Router) *mux.R
return m
}
log.G(ctx).WithFields(log.Fields{"method": r.Method(), "path": r.Path()}).Debug("Registering route")
f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path())
f := s.makeHTTPHandler(r)
m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f)
m.Path(r.Path()).Methods(r.Method()).Handler(f)
}