-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
49 lines (42 loc) · 1.27 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
package main
// fasthttpsession redis provider example
import (
"github.com/phachon/fasthttpsession"
"github.com/valyala/fasthttp"
"log"
"os"
"github.com/phachon/fasthttpsession/mysql"
)
// 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("mysql", mysql.NewConfigWith("127.0.0.1", 3306, "root", "admin", "test", "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())
}
}