Skip to content
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

context.Next() #105

Open
achempak-polymer opened this issue Apr 22, 2023 · 1 comment
Open

context.Next() #105

achempak-polymer opened this issue Apr 22, 2023 · 1 comment

Comments

@achempak-polymer
Copy link

The docs say that examples using next should be present in this repo (https://pkg.go.dev/github.com/gin-gonic/gin#Context.Next). I'm a bit confused on the lifecycle of middleware. For example, say we have the following middleware:

func timerMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		t1 := time.Now()
		c.Next()
                t2 := time.Now().Sub(t1)
                c.Header("time", t2.Seconds())
	}
}

My goal here is to include the time it took to process the request as a response header. Is the above correct way of doing this?

@FarmerChillax
Copy link

you are right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants