Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go-gin unable to set cookies

Tags:

cookies

go

go-gin

I am trying to set a cookie on an HTML page

 func testCookie(c *gin.Context) {
    c.SetCookie("test1", "testvalue", 10, "/", "", true, true)
    c.HTML(200, "dashboard", gin.H{
        "title":    "Dashboard",
        }
    }

This should have set the cookie on the HTML page but it doesn't. My server is running to serve https requests. I am not sure why I am not able to set cookies here.

like image 881
codec Avatar asked Oct 25 '25 08:10

codec


1 Answers

Adding to comments above Try using

c.SetCookie("cookieName", "name", 10, "/", "yourDomain", true, true)

example

c.SetCookie("gin_cookie", "someName", 60*60*24, "/", "google.com", true, true)
like image 158
Mendo Avatar answered Oct 27 '25 01:10

Mendo