go-gin unable to set cookies

codec picture codec · Nov 30, 2016 · Viewed 8.2k times · Source

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.

Answer

Mendo picture Mendo · Apr 8, 2019

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)