Go原生和GoFrame的Cookie关于MaxAge区别
Go原生和GoFrame的Cookie关于MaxAge区别
环境:
-
gf v1.14.4
-
go 1.11
Go原生
type Cookie struct {
Name string
Value string
Path string
Domain string
Expires time.Time
RawExpires string
// MaxAge=0表示未设置Max-Age属性
// MaxAge<0表示立刻删除该cookie,等价于"Max-Age: 0"
// MaxAge>0表示存在Max-Age属性,单位是秒
MaxAge int
Secure bool
HttpOnly bool
Raw string
Unparsed []string // 未解析的“属性-值”对的原始文本
}
MaxAge=0表示未设置Max-Age属性,即生命周期为session,关闭浏览器当前Cookie即失效。
GoFrame
// Cookie for HTTP COOKIE management.
type Cookie struct {
data map[string]*http.Cookie // Underlying cookie items.
path string // The default cookie path.
domain string // The default cookie domain
maxAge time.Duration // The default cookie max age.
server *Server // Belonged HTTP server
request *Request // Belonged HTTP request.
response *Response // Belonged HTTP response.
}
在设置Cookie变量的时候可以给定过期时间,该时间为可选参数,默认的Cookie过期时间为一年。
暂时未提供MaxAge=session的选项,只有时间参数,以及-1立即销毁选项可供设置。
结合应用场景做自己的选择,也可以在GoFrame下使用Go原生Cookie进行该选项的设置。

浙公网安备 33010602011771号