@@ -63,18 +63,20 @@ func (r *router) Run(ctx context.Context) error {
6363// HTTP ROUTER
6464
6565// Register a function to handle a URL path
66- func (r * router ) HandleFunc (ctx context.Context , prefix string , fn http.HandlerFunc ) {
66+ func (r * router ) HandleFunc (parent context.Context , prefix string , fn http.HandlerFunc ) {
6767 // Wrap the function with middleware
6868 for _ , middleware := range r .middleware {
6969 fn = middleware .HandleFunc (fn )
7070 }
7171
7272 // Apply middleware, set context
73- ref .Log (ctx ).Debug (ctx , "Register route: " , types .JoinPath (r .prefix , prefix ))
73+ ref .Log (parent ).Debug (parent , "Register route: " , types .JoinPath (r .prefix , prefix ))
7474 r .ServeMux .HandleFunc (types .JoinPath (r .prefix , prefix ), func (w http.ResponseWriter , r * http.Request ) {
75- r = r .WithContext (ref .WithLog (r .Context (), ref .Log (ctx )))
76- // TODO: Add Log into the r context, but don't replace the original
77- fn (w , r )
75+ // Add provider to context
76+ ctx := ref .WithProvider (r .Context (), ref .Provider (parent ))
77+
78+ // Serve the request
79+ fn (w , r .WithContext (ctx ))
7880 })
7981}
8082
@@ -84,7 +86,7 @@ func (r *router) Origin() string {
8486}
8587
8688// Register serving of static files from a filesystem
87- func (r * router ) HandleFS (ctx context.Context , prefix string , fs fs.FS ) {
89+ func (r * router ) HandleFS (parent context.Context , prefix string , fs fs.FS ) {
8890 // Create the file server
8991 fn := http .StripPrefix (types .JoinPath (r .prefix , prefix ), http .FileServer (http .FS (fs ))).ServeHTTP
9092
@@ -94,12 +96,12 @@ func (r *router) HandleFS(ctx context.Context, prefix string, fs fs.FS) {
9496 }
9597
9698 // Apply middleware
97- ref .Log (ctx ).Debug (ctx , "Register route : " , types .JoinPath (r .prefix , prefix ))
99+ ref .Log (parent ).Debug (parent , "Register static : " , types .JoinPath (r .prefix , prefix ))
98100 r .ServeMux .HandleFunc (types .JoinPath (r .prefix , prefix ), func (w http.ResponseWriter , req * http.Request ) {
99101 // Set CORS headers
100102 httpresponse .Cors (w , req , r .origin , http .MethodGet )
101103
102104 // Call the file server
103- fn (w , req .WithContext (ref .WithLog ( ctx , ref .Log ( ctx ))))
105+ fn (w , req .WithContext (ref .WithProvider ( parent , ref .Provider ( parent ))))
104106 })
105107}
0 commit comments