-
Notifications
You must be signed in to change notification settings - Fork 7
/
cookie.go
40 lines (36 loc) · 919 Bytes
/
cookie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @Author: DollarKiller
* @Description: session or cookie
* @Github: https://github.com/dollarkillerx
* @Date: Create in 14:16 2019-10-12
*/
package erguotou
import (
"github.com/dollarkillerx/erguotou/fasthttp"
"time"
)
func (c *Context) GetCookie(key string) string {
return string(c.Ctx.Request.Header.Cookie(key))
}
func (c *Context) SetCookie(key string, val string) {
cookie := fasthttp.Cookie{}
cookie.SetKey(key)
cookie.SetValue(val)
cookie.SetHTTPOnly(true)
cookie.SetPath("/")
c.Ctx.Response.Header.SetCookie(&cookie)
}
func (c *Context) SetCookieTime(key, val string, ti time.Duration) {
cookie := fasthttp.Cookie{}
cookie.SetKey(key)
cookie.SetValue(val)
cookie.SetHTTPOnly(true)
cookie.SetPath("/")
//duration := time.Second * 1000
////time := time.Now() + duration
////ti
//now := time.Now()
//now.Hour() =
//cookie.SetExpire()
c.Ctx.Response.Header.SetCookie(&cookie)
}