[golang] How to set cookie under gin
setcookie example:
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/cookie", func(c *gin.Context) {
// 设置cookie
c.SetCookie("site_cookie", "cookievalue", 3600, "/", "localhost", false, true)
})
router.Run()
}
SetCookie函数定义:
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
special note: domain string must be correct. if not , SetCookie will be not write into right place.
source: https://www.tizi365.com/archives/273.html