首先先放出golang cookie的结构
type Cookie struct {
Name string
Value string
Path string // optional
Domain string // optional
Expires time.Time // optional
RawExpires string // for reading cookies only
// MaxAge=0 means no 'Max-Age' attribute specified.
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
// MaxAge>0 means Max-Age attribute present and given in seconds
MaxAge int
Secure bool
HttpOnly bool
SameSite SameSite
Raw string
Unparsed []string // Raw text of unparsed attribute-value pairs
}
1.cookie的过期时间
有两种方式,1 设定expires 2设定maxAge
区别:expires是指定cookie在某一个时刻过期,而maxAge是设定经过多少秒后过期。
之所以出现这两种方式,是因为不同的浏览器对cookie有不同的实现机制,HTTP1.1推荐使用maxAge代替expires,但IE系列的IE6、IE7、IE8不支持maxAge,为了让所有的浏览器都能够正常工作,实际的方法是只使用expires,或者两者都用