2017-02-15 19:06:19 +01:00
|
|
|
package main
|
|
|
|
|
2017-06-07 21:14:13 +02:00
|
|
|
// 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
|
2017-02-15 19:06:19 +01:00
|
|
|
|
2017-06-07 21:14:13 +02:00
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/sessions"
|
2017-06-07 21:14:13 +02:00
|
|
|
|
2020-05-07 06:34:17 +02:00
|
|
|
"github.com/kataras/iris/v12/_examples/sessions/overview/example"
|
|
|
|
|
2017-06-07 21:14:13 +02:00
|
|
|
"github.com/gorilla/securecookie"
|
2017-02-15 19:06:19 +01:00
|
|
|
)
|
|
|
|
|
2017-07-11 17:09:32 +02:00
|
|
|
func newApp() *iris.Application {
|
2017-02-15 19:06:19 +01:00
|
|
|
app := iris.New()
|
|
|
|
|
2020-05-07 06:34:17 +02:00
|
|
|
cookieName := "_session_id"
|
2017-03-18 22:43:04 +01:00
|
|
|
// 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 := []byte("the-big-and-secret-fash-key-here")
|
|
|
|
blockKey := []byte("lot-secret-of-characters-big-too")
|
|
|
|
secureCookie := securecookie.New(hashKey, blockKey)
|
|
|
|
|
2017-02-15 19:06:19 +01:00
|
|
|
mySessions := sessions.New(sessions.Config{
|
2018-06-25 19:21:52 +02:00
|
|
|
Cookie: cookieName,
|
|
|
|
Encode: secureCookie.Encode,
|
|
|
|
Decode: secureCookie.Decode,
|
|
|
|
AllowReclaim: true,
|
2017-02-15 19:06:19 +01:00
|
|
|
})
|
|
|
|
|
2020-05-07 06:34:17 +02:00
|
|
|
app = example.NewApp(mySessions)
|
2017-07-11 17:09:32 +02:00
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := newApp()
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2017-02-15 19:06:19 +01:00
|
|
|
}
|