get req from ctx (#975)

Co-authored-by: longXboy <longxboy@gmail.com>
pull/982/head
longxboy 4 years ago committed by GitHub
parent f51bd97324
commit 930d1f6cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      middleware/metrics/metrics.go

@ -54,12 +54,13 @@ func Server(opts ...Option) middleware.Middleware {
method = "POST"
path = info.FullMethod
} else if info, ok := http.FromServerContext(ctx); ok {
method = info.Request.Method
if route := mux.CurrentRoute(info.Request); route != nil {
req := info.Request.WithContext(ctx)
method = req.Method
if route := mux.CurrentRoute(req); route != nil {
// /path/123 -> /path/{id}
path, _ = route.GetPathTemplate()
} else {
path = info.Request.RequestURI
path = req.RequestURI
}
}
startTime := time.Now()

Loading…
Cancel
Save