We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func AddLogUserId() func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() value := ctx.Value("userid") ctx = logx.ContextWithFields(ctx, logx.LogField{ Key: "userid", Value: value, }) next.ServeHTTP(w, r.WithContext(ctx)) }) } }
The text was updated successfully, but these errors were encountered:
mybe there's no way... http log handler called before auth handler where userid set to ctx
func (ng *engine) bindRoute(fr featuredRoutes, router httpx.Router, metrics *stat.Metrics, route Route, verifier func(chain.Chain) chain.Chain) error { chn := ng.chain if chn == nil { chn = ng.buildChainWithNativeMiddlewares(fr, route, metrics) // <--- http log } chn = ng.appendAuthHandler(fr, chn, verifier) // <--- set userid to ctx for _, middleware := range ng.middlewares { chn = chn.Append(convertMiddleware(middleware)) // <-- read from ctx then set to log filed } handle := chn.ThenFunc(route.Handler) return router.Handle(route.Method, route.Path, handle) }
Sorry, something went wrong.
You can svr.WithMiddleware(...) to achive this goal.
svr.WithMiddleware(...)
No branches or pull requests
how can i do?
The text was updated successfully, but these errors were encountered: