forked from phachon/fasthttpsession
/
main.go
56 lines (49 loc) · 1.34 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
package main
// fasthttpsession redis provider example
import (
"github.com/phachon/fasthttpsession"
"github.com/valyala/fasthttp"
"log"
"os"
"github.com/phachon/fasthttpsession/memcache"
)
// 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("memcache", &memcache.Config{
ServerList: []string{
"127.0.0.1:21122",
"127.0.0.1:21123",
},
MaxIdle: 8,
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())
}
}