mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 11:11:03 +01:00
cd62ba3712
Former-commit-id: 682472d2cf4ebfc740687522fe5eef77b5bb1a72
41 lines
783 B
Go
41 lines
783 B
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/sessions"
|
|
"github.com/kataras/iris/v12/sessions/sessiondb/badger"
|
|
|
|
"github.com/kataras/iris/v12/_examples/sessions/overview/example"
|
|
)
|
|
|
|
func main() {
|
|
db, err := badger.New("./data")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// close and unlock the database when control+C/cmd+C pressed
|
|
iris.RegisterOnInterrupt(func() {
|
|
db.Close()
|
|
})
|
|
|
|
defer db.Close() // close and unlock the database if application errored.
|
|
|
|
sess := sessions.New(sessions.Config{
|
|
Cookie: "sessionscookieid",
|
|
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
|
AllowReclaim: true,
|
|
})
|
|
|
|
//
|
|
// IMPORTANT:
|
|
//
|
|
sess.UseDatabase(db)
|
|
|
|
app := example.NewApp(sess)
|
|
app.Listen(":8080")
|
|
}
|