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
r.group not working #108
Comments
You are referencing the same "group". // notify the "test" variable
test := r.Group("/", TestHandle())
test.GET("/test", func(c *gin.Context) {
fmt.Printf("test")
c.String(200, "ok")
}) I, personally, like to use the brackets because it gives a sense of group, and makes the routes easier to read. // notify the "test" variable
test := r.Group("/", TestHandle())
{
test.GET("/test", func(c *gin.Context) {
fmt.Printf("test")
c.String(200, "ok")
})
} It's exactly the same. |
anyway, I am more worried about "[GIN] WARNING. Headers were already written!" |
Ah ok, did not know I had to use thegroupname.GET :-) Thanks! |
anyway, could you post the code? that warning should never appear |
Its a lot of code so i`ll keep it simple: func MongoAuth() gin.HandlerFunc {
return func(c *gin.Context) {
fmt.Printf("TEST: \n" )
cookie := c.Request.Header.Get("Cookie")
fmt.Printf("cookie: %v\n", cookie)
c.Next()
fmt.Printf("TEST2: \n" )
}
}
func main() {
db := database.GDatabase{}
db.Initialize()
gs := Server{}
gs.db = &db
....
// no more rabbit for the moment
//gs.initialize_rabbit()
r := gin.Default()
r.Group("/", MongoAuth())
{
r.GET("/test", func(c *gin.Context) {
fmt.Printf("test")
c.String(200, "ok")
})
///////
// Bitbucket
r.GET("/auth/login/bitbucket", func(c *gin.Context) {
... logic here ...
c.Redirect(301, "http://localhost:8080/wert")
})
r.GET("/auth/login/bitbucket/token", func(c *gin.Context) {
... logic here ...
fmt.Printf("url: %s\n", url)
if strings.EqualFold("", url) {
c.String(503, "Internal error")
}
c.Redirect(301, url)
})
}
} |
@RoelVanNyen sorry for the delay Pretty sure your warning about headers is related because you write to the response before trying to redirect. |
I made a quick test with custom middleware groups:
TEST and TEST2 never gets printed.
I do get a warning:
[GIN] WARNING. Headers were already written!
Any ideas ?
The text was updated successfully, but these errors were encountered: