// 设置 cookie
cookie2 := new(http.Cookie)
cookie2.Name = "imageId"
cookie2.Value = imageId
cookie2.Expires = time.Now().Add(24 * time.Hour)
ctx.SetCookie(cookie2)
// 读取 cookie
cookie, err := ctx.Cookie("imageId")
if err != nil {
return err
}
fmt.Println("name:" + cookie.Name);
fmt.Println("value:" + cookie.Value);
for _, cookie := range ctx.Cookies() {
fmt.Println("Name:" + cookie.Name)
fmt.Println("Value:" + cookie.Value)
}
有种常用的场景需要注意:A服务访问 B go服务,go服务设置cookie后,无法获取,会报错:http: named cookie not present 这种情况可以使用session存储数据www.tizi365.com/archives/73…