Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 11:23
    Cyberpunk314 commented #29
  • Aug 10 13:33
    Stolr commented #3254
  • Aug 10 09:12
    jabielecki commented #1605
  • Aug 10 09:02
    jabielecki commented #1605
  • Aug 10 09:02
    jabielecki commented #1605
  • Aug 10 07:41
    KKRaver commented #3267
  • Aug 10 03:06
    centratelemedia closed #3274
  • Aug 10 03:06
    centratelemedia commented #3274
  • Aug 09 19:44
    centratelemedia commented #3274
  • Aug 09 16:38
    KKRaver commented #3274
  • Aug 09 15:23
    Gasoid commented #3114
  • Aug 09 15:14
    Gasoid commented #3266
  • Aug 09 15:10
    Gasoid commented #3271
  • Aug 09 15:10
    Gasoid commented #3271
  • Aug 09 12:47
    StephanoGeorge commented #3270
  • Aug 09 09:49
    centratelemedia edited #3274
  • Aug 09 09:49
    centratelemedia opened #3274
  • Aug 08 22:24
    codecov[bot] commented #3273
  • Aug 08 22:24
    Coverage (#3273) +0.00%
  • Aug 08 22:21
    codecov[bot] commented #3273
It is very urgent and I hope you can bring it to your attention


When to deal with that?

Kevin Graham
I add a cors middleware to gin router
but the front request still been blocked
Sunil Joshi
Sorry wrong winow
Romeo Mihalcea
any ideas of a middleware that allows you to add a timeout per request? Except for this one which is bugged: https://github.com/gin-contrib/timeout
Has anyone ever tested websockets while using gin and gorilla websocket
Phillip Couto
@romeo.mihalcea:matrix.org I would look at context.Context and create a middleware that will reassign the c.Request.Context. The only way this works though is if all the code in your handlers are using the c.Request.Context so they cancel when the timeout occurs.
Maybe I can find time this week to create one if you have trouble.
I save session when login, but I can't get session when upload file.
Can anyone help?
The main function,
sess := r.Group("/", pkg.EnableCookieSession())
        sess.POST("/login", post.Login)

         * Got problem here, session not working...
        authorized := sess.Group("/auth", pkg.AuthSessionMiddle)
        // authorized := sess.Group("/auth")
            authorized.POST("/upload", post.Upload)
            authorized.POST("/webshell", post.WebShell)
            authorized.StaticFS("/download", http.Dir("download"))
    err := r.Run(":3333")
    // err := r.RunTLS(":3333", "server.crt", "server.key")
    if err != nil {
My Login function,
func Login(c *gin.Context) {
    tableName := "user_passwd"
    username := c.PostForm("username")
    password := c.PostForm("password")
    passwordMd5Form := fmt.Sprintf("%x", md5.Sum([]byte(password)))

    db, err := sql.Open("mysql", "root:hushanglai@tcp(localhost:3306)/web")
    if err != nil {
        log.Printf("sql.Open: %v", err)
    defer func(db *sql.DB) {
        err := db.Close()
        if err != nil {
            log.Printf("Fail to close db:%v", err)

    // Query password for a specified username
    sqlString := fmt.Sprintf("select password from %s where username=\"%s\"",
        tableName, username)

    res, err := db.Query(sqlString)
    defer func(res *sql.Rows) {
        err := res.Close()
        if err != nil {
            log.Printf("res.Close: %v", err)
    if err != nil {
        log.Printf("db.Query: %v", err)

    var passwordMd5Mysql string
    for res.Next() {
        err = res.Scan(&passwordMd5Mysql)
        if err != nil {
            c.String(http.StatusUnauthorized, "username or password wrong!")
    if passwordMd5Mysql != passwordMd5Form {
        c.String(http.StatusUnauthorized, "username or password wrong!")
    c.String(http.StatusOK, "Login successful")

    pkg.SaveAuthSession(c, username)
    c.JSON(http.StatusOK, gin.H{"message": "Successfully authenticated user"})
My pkg.SaveAuthSession,
func SaveAuthSession(c *gin.Context, username string) {
    session := sessions.Default(c)
    session.Set("user", username)
    err := session.Save()
    if err != nil {
        c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to save session"})
    c.JSON(http.StatusOK, gin.H{"message": "save session ok"})

My pkg.AuthSessionMiddle function,

func AuthSessionMiddle(c *gin.Context) {
    session := sessions.Default(c)
    sessionValue := session.Get("user")
    if sessionValue == nil {
        c.JSON(http.StatusUnauthorized, gin.H{
            "error": "Unauthorized",
    // c.Set("userId", sessionValue.(uint))

My problem is here, sessionValue := session.Get("user") won't get the session, I don't know why.

I am new to Go, can anyone help?
Thank you.
Sorry, my problem is here, session := sessions.Default(c) won't get the session that Login function saves.
I think sessions.Default(c) should return the session that Login() saves.
Phillip Couto
Where is the sessions suppose to be saved? In the cookie?
Steve McDaniel
I am testing using the autotls with gin and I keep getting http: TLS handshake error from ... acme/autocert: missing server name
I am running with err = autotls.Run(r, "api.myvaliddomain.com")
I am not exactly sure what the issue is, but I am running my gin app inside of docker with ports 80 and 443 forwarded
Raphaël Yancey
Hi :)
One of my Gin route handler starts a goroutine to handle the request in order to returns 200 asap (it's an event handler and the caller doesn't except any response).
I'm having a hard time testing that the goroutine is called, and testing what happens in it. Do you guys have any advice on the approach I should take?
Nikolay Kiselev
Hi, are there any updates on new logo proposal gin-gonic/logo#6? This logo variant has more than 400 upvotes on reddit
Fabrizio Sestito
Hi everyone, I'm struggling with gin not overriding a status code with a 500 if the error is caused from a method called in a template
Narsimham Chelluri
Hello, I have a question about data binding. Is it possible to normalize the data that comes out of the Bind functions? E.g. uppercase it, massage it, etc.

Go Gin reCAPTCHA Example (v2 & v3)


the forum is dead?
Pooja Yadav
Hi everyone, Pooja here. I work as a Senior Marketing Coordinator at Packt. Looking at all the talk around Gin has encouraged me to share that Packt recently released a book on the framework. Building Distributed Applications in Gin: https://packt.link/niS8s by Mohamed Labouardy, do check the book and you can approach me if you'll like to have a free digital copy.
@PoojaYa01281608_twitter I did like to have a free digital copy.
Pooja Yadav
Sure, let's discuss in private.
Juan Pablo Tosso
Hey guys, I just integrated coraza-waf (A web application firewall) with Gin, I'm not a gin user so it's hard for me to write tests. I hope someone can check my project :) https://github.com/jptosso/coraza-gin
Yordis Prieto

Hey folks, I am fairly new into Go, and Gin. I am trying to figure out how to do the following

// I need to do this
if validate, ok := binding.Validator.Engine().(*validator.Validate); ok {

But I would like to do it at the router level

router := gin.New()
// can I do the binding validator thingy using `router` somehow?
Basically, how to remove that binding.Validator singleton setup
Jeroen Bulters
Hi all! Looking for a way to use ShouldBind with embedded structs. Basically trying to bind a form posted field "Config.Name" to the Name field in the embedded Config struct.
Any "prior art"? ;-)
anyone there?
i cant clone
go get -u github.com/gin-gonic/gin
# cd .; git clone -- https://gopkg.in/yaml.v2 /Users/jt/golib/src/gopkg.in/yaml.v2
Cloning into '/Users/jt/golib/src/gopkg.in/yaml.v2'...
fatal: unable to access 'https://gopkg.in/yaml.v2/': SSL certificate problem: certificate has expired
package gopkg.in/yaml.v2: exit status 128
Hello devs! I would like to you to help me out with your opinions. Me & my team have a interesting social networking project on the table. We would like to build it using Go lang. How much do you recommend Gin Gonic for such a project? I'm just doing research on the best possible Go lang frameworks.
2 replies
How can I make a middleware that modifies after next call the headers like?
func ResponseTimeMiddleware(c *gin.Context) {
    startTime := GetUnixTime()
    c.Request.Header.Add("x-response-time", strconv.FormatInt(GetUnixTime()-startTime, 10))
I might be an idiot.
But running go get github.com/gin-contrib/sessions is returning ../../go/pkg/mod/github.com/gin-contrib/sessions@v0.0.4/session_options_go1.10.go:1:1: expected 'package', found 'EOF'
Any ideas?
Danny Lai


I am writing a simple API with gin. routes / request / response all good. Now, i am trying to add some debugs into the route. I know i can log.Print() the messages, but with that, i will not have the context (request id, request body / method etc). I tried looking up a logger middleware that can accept any debug message (log.Print("Working on request" + param.Request.Body)).. but i can't seem to find any. All that said, question: How i can print debug message within a route, such that it has the context, and any debug messages i left in the route? Any example would be great!