-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
38 lines (30 loc) · 1.01 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
package main
// developers can use any library to add a custom cookie encoder/decoder.
// At this example we use the gorilla's securecookie package:
// $ go get github.com/gorilla/securecookie
// $ go run main.go
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
"github.com/kataras/iris/v12/_examples/sessions/overview/example"
"github.com/gorilla/securecookie"
)
func newApp() *iris.Application {
cookieName := "_session_id"
// AES only supports key sizes of 16, 24 or 32 bytes.
// You either need to provide exactly that amount or you derive the key from what you type in.
hashKey := securecookie.GenerateRandomKey(64)
blockKey := securecookie.GenerateRandomKey(32)
s := securecookie.New(hashKey, blockKey)
mySessions := sessions.New(sessions.Config{
Cookie: cookieName,
Encoding: s,
AllowReclaim: true,
})
// mySessions.UseDatabase(...see sessions/database example folder)
return example.NewApp(mySessions)
}
func main() {
app := newApp()
app.Listen(":8080")
}