-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
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
how can i get response time through middlerware? #25
Comments
Do you need the time spent in the handler, middleware or in all?. |
@savsgio Need before and after middleware |
yes |
@r6c using master branch // your_middleware.go
const (
uvKey = "request.startTime"
millisecond = float64(time.Millisecond)
)
func BeforeChain(ctx *atreugo.RequestCtx) (int, error) {
ctx.SetUserValue(uvKey, Nanotime())
return fasthttp.StatusOK, nil
}
func AfterChain(ctx *atreugo.RequestCtx) (int, error) {
startTime := *(*int64)(runtimer.GetEfaceDataPtr(ctx.UserValue(uvKey)))
duration := float64(Nanotime()-startTime) / millisecond
return fasthttp.StatusOK, nil
}
// main.go
server.UseBefore(yourMiddleware.BeforeChain)
server.UseAfter(yourMiddleware.AfterChain) |
thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i want to get response time, how can i do?
The text was updated successfully, but these errors were encountered: