Giter VIP home page Giter VIP logo

Comments (6)

manucorporat avatar manucorporat commented on April 25, 2024

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.

manucorporat avatar manucorporat commented on April 25, 2024

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.

RoelVanNyen avatar RoelVanNyen commented on April 25, 2024

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.

manucorporat avatar manucorporat commented on April 25, 2024

anyway, could you post the code? that warning should never appear

from gin.

RoelVanNyen avatar RoelVanNyen commented on April 25, 2024

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.

javierprovecho avatar javierprovecho commented on April 25, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.