2017-09-24 13:32:16 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2017-09-24 13:32:16 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/sessions"
|
|
|
|
"github.com/kataras/iris/v12/sessions/sessiondb/badger"
|
2020-05-07 06:34:17 +02:00
|
|
|
|
|
|
|
"github.com/kataras/iris/v12/_examples/sessions/overview/example"
|
2017-09-24 13:32:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2018-04-22 12:52:36 +02:00
|
|
|
defer db.Close() // close and unlock the database if application errored.
|
|
|
|
|
2017-09-24 13:32:16 +02:00
|
|
|
sess := sessions.New(sessions.Config{
|
2018-06-25 19:21:52 +02:00
|
|
|
Cookie: "sessionscookieid",
|
|
|
|
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
|
|
|
AllowReclaim: true,
|
2017-09-24 13:32:16 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
//
|
|
|
|
// IMPORTANT:
|
|
|
|
//
|
|
|
|
sess.UseDatabase(db)
|
|
|
|
|
2020-05-07 06:34:17 +02:00
|
|
|
app := example.NewApp(sess)
|
2020-04-28 04:22:58 +02:00
|
|
|
app.Listen(":8080")
|
2017-09-24 13:32:16 +02:00
|
|
|
}
|