ft: module_name wrapper middleware

This commit is contained in:
mayur.popli
2025-04-04 15:01:15 +05:30
parent 4278812c48
commit d1e8716e15
5 changed files with 32 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ func Register(ctx context.Context, mCfgs []Config, mux *http.ServeMux, mgr handl
return fmt.Errorf("failed to add middleware: %w", err)
}
h = moduleCtxMiddleware(c.Name, h)
log.Debugf(ctx, "Registering handler %s, of type %s @ %s", c.Name, c.Handler.Type, c.Path)
mux.Handle(c.Path, h)
}
@@ -71,3 +72,10 @@ func addMiddleware(ctx context.Context, mgr handler.PluginManager, handler http.
log.Debugf(ctx, "Middleware chain setup completed")
return handler, nil
}
func moduleCtxMiddleware(moduleName string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), "module_name", moduleName)
next.ServeHTTP(w, r.WithContext(ctx))
})
}