mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 03:01:03 +01:00
cd62ba3712
Former-commit-id: 682472d2cf4ebfc740687522fe5eef77b5bb1a72
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
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 {
|
|
app := iris.New()
|
|
|
|
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 := []byte("the-big-and-secret-fash-key-here")
|
|
blockKey := []byte("lot-secret-of-characters-big-too")
|
|
secureCookie := securecookie.New(hashKey, blockKey)
|
|
|
|
mySessions := sessions.New(sessions.Config{
|
|
Cookie: cookieName,
|
|
Encode: secureCookie.Encode,
|
|
Decode: secureCookie.Decode,
|
|
AllowReclaim: true,
|
|
})
|
|
|
|
app = example.NewApp(mySessions)
|
|
return app
|
|
}
|
|
|
|
func main() {
|
|
app := newApp()
|
|
app.Listen(":8080")
|
|
}
|