Comments (6)
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.
from gin.
anyway, I am more worried about "[GIN] WARNING. Headers were already written!"
please can you share all the code? and tell me if you still get that warning?
from gin.
Ah ok, did not know I had to use thegroupname.GET :-)
This fixes the problem, now my code works and the warning is gone.
Thanks!
from gin.
anyway, could you post the code? that warning should never appear
from gin.
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)
})
}
}
from gin.
@RoelVanNyen sorry for the delay
Pretty sure your warning about headers is related because you write to the response before trying to redirect.
from gin.
Related Issues (20)
- Can't get status as expected from context.Status() HOT 1
- Gin Context implementation breaks context.Context contract HOT 4
- [Suggestions] Introducing an AI-powered robot to assist with daily issue and pull request (PR) tasks.
- Need c.JSON() response like behaviour for c.SSEvent() response for supporting first party clients like OpenAI SDK HOT 2
- custom time.Time type can not use bindQuery get a value. HOT 3
- configure server parameters HOT 1
- The binding:"required" tag does not seem to work for struct types HOT 3
- Is there a way to preserve order in JSON on response? HOT 1
- redirect is not success HOT 1
- I want to use shouldmindbodywith first and then use formafile, but it doesn't work right now HOT 3
- Extend the routing tree entry
- Transparent decompression for gzip, deflate, etc? HOT 1
- Custom time.Time type can not use bindQuery get a value 2 HOT 2
- http: response.Write on hijacked connection from github.com/gin-gonic/gin.(*responseWriter).Write (response_writer.go:83) HOT 1
- Suggestion: Move Print Debug to Run() functions? HOT 7
- AbortWithStatusJSON doesn't abort context HOT 2
- I translated `tree.go` into java
- GetUint and GetUint64 wrong return HOT 1
- Multipart form-data request with empty key for single file upload
- gin with golang 1.21, 1.22 DATA RACE
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gin.