这是我的代码,我从go-gin框架文档中复制了它,我的问题是当createCookie函数命中时,它返回"NotSet“,我必须运行相同的API回调来获取cookie。
// createCookie accepts c as gin context and create cookies
func createCookie(c *gin.Context) (string, error) {
cookie, err := c.Cookie("device")
if err != nil {
cookie = "NotSet"
c.SetCookie("device", "test", 3600, "/", os.Getenv("AUTH_DOMAIN"), true, true)
}
return cookie, nil
}发布于 2021-10-18 16:12:04
// createCookie accepts c as gin context and create cookies
func createCookie(c *gin.Context) (string, error) {
cookie, err := c.Cookie("device")
if err != nil {
// Replae it with your initial value
cookie = "NotSet"
c.SetCookie("device", cookie, 3600, "/", os.Getenv("AUTH_DOMAIN"), true, true)
}
return cookie, nil
}https://stackoverflow.com/questions/69619222
复制相似问题