forked from linuxpham/fasthttpsession
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 1.36 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
// fasthttpsession redis provider example
import (
"log"
"os"
"github.com/brunohass/fasthttpsession"
"github.com/brunohass/fasthttpsession/redis"
"github.com/valyala/fasthttp"
)
// default config
var session = fasthttpsession.NewSession(fasthttpsession.NewDefaultConfig())
// custom config
//var session = fasthttpsession.NewSession(&fasthttpsession.Config{
// CookieName: "ssid",
// Domain: "",
// Expires: time.Hour * 2,
// GCLifetime: 3,
// SessionLifetime: 60,
// Secure: true,
// SessionIdInURLQuery: false,
// SessionNameInUrlQuery: "",
// SessionIdInHttpHeader: false,
// SessionNameInHttpHeader: "",
// SessionIdGeneratorFunc: func() string {return ""},
// EncodeFunc: func(cookieValue string) (string, error) {return "", nil},
// DecodeFunc: func(cookieValue string) (string, error) {return "", nil},
//})
func main() {
// You must set up provider before use
err := session.SetProvider("redis", &redis.Config{
Host: "127.0.0.1",
Port: 6379,
MaxIdle: 8,
IdleTimeout: 300,
Password: "123456",
KeyPrefix: "session",
})
if err != nil {
log.Println(err.Error())
os.Exit(1)
}
addr := ":8086"
log.Println("fasthttpsession redis example server listen: " + addr)
// Fasthttp start listen serve
err = fasthttp.ListenAndServe(addr, requestRouter)
if err != nil {
log.Println("listen server error :" + err.Error())
}
}