parent
6659a381ea
commit
b15d01b0ce
6 changed files with 28 additions and 28 deletions
|
@ -121,7 +121,7 @@ func wrapHandlerProvider[T http.Handler](hp func(next http.Handler) T, funcInfo
|
|||
return func(next http.Handler) http.Handler {
|
||||
h := hp(next) // this handle could be dynamically generated, so we can't use it for debug info
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
routing.UpdateFuncInfo(req.Context(), funcInfo)
|
||||
defer routing.RecordFuncInfo(req.Context(), funcInfo)()
|
||||
h.ServeHTTP(resp, req)
|
||||
})
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ func toHandlerProvider(handler any) func(next http.Handler) http.Handler {
|
|||
return // it's doing pre-check, just return
|
||||
}
|
||||
|
||||
routing.UpdateFuncInfo(req.Context(), funcInfo)
|
||||
defer routing.RecordFuncInfo(req.Context(), funcInfo)()
|
||||
ret := fn.Call(argsIn)
|
||||
|
||||
// handle the return value (no-op at the moment)
|
||||
|
|
|
@ -12,16 +12,18 @@ type contextKeyType struct{}
|
|||
|
||||
var contextKey contextKeyType
|
||||
|
||||
// UpdateFuncInfo updates a context's func info
|
||||
func UpdateFuncInfo(ctx context.Context, funcInfo *FuncInfo) {
|
||||
record, ok := ctx.Value(contextKey).(*requestRecord)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// RecordFuncInfo records a func info into context
|
||||
func RecordFuncInfo(ctx context.Context, funcInfo *FuncInfo) (end func()) {
|
||||
// TODO: reqCtx := reqctx.FromContext(ctx), add trace support
|
||||
end = func() {}
|
||||
|
||||
record.lock.Lock()
|
||||
record.funcInfo = funcInfo
|
||||
record.lock.Unlock()
|
||||
// save the func info into the context record
|
||||
if record, ok := ctx.Value(contextKey).(*requestRecord); ok {
|
||||
record.lock.Lock()
|
||||
record.funcInfo = funcInfo
|
||||
record.lock.Unlock()
|
||||
}
|
||||
return end
|
||||
}
|
||||
|
||||
// MarkLongPolling marks the request is a long-polling request, and the logger may output different message for it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue