go version go1.12.9 linux/amd64 github.com/gin-gonic/gin v1.4.0

When i want set cookie, and read cookie, is not work:

Code:

package main

import (
    "log"
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    router := gin.Default()
    router.GET("/", func(context *gin.Context) {
        log.Println("before set cookie,show cookies:", context.Request.Cookies())
        context.SetCookie("userCookie", "test", 1000, "/", "localhost", false, true)
        log.Println("after set cookie,show cookies:", context.Request.Cookies())
        _, err := context.Request.Cookie("userCookie")
        if err != nil {
            log.Println(err.Error())

        }
        context.String(http.StatusOK, "INDEX")
    })
    _ = router.Run()
}

Log:

[GIN-debug] Listening and serving HTTP on :8080
2019/08/28 11:13:15 before set cookie,show cookies: [pga4_session=45a6cacd-7775-4ad6-8591-fcdc9a633e45!WwkgKWYfD+8187cf7fgM9QWhe88=]
2019/08/28 11:13:15 after set cookie,show cookies: [pga4_session=45a6cacd-7775-4ad6-8591-fcdc9a633e45!WwkgKWYfD+8187cf7fgM9QWhe88=]
2019/08/28 11:13:15 http: named cookie not present
[GIN] 2019/08/28 - 11:13:15 | 200 |     180.379µs | 192.168.124.100 | GET      /

Comment From: MushiTheMoshi

how did you fix this?