baa middleware for provides the session management.
- redis
- memory
package main
import (
"github.com/go-baa/baa"
"github.com/baa-middleware/session"
)
func main() {
// new app
app := baa.New()
// use session middleware
redisOptions := session.RedisOptions{}
redisOptions.Addr = "127.0.0.1:6379"
redisOptions.Prefix = "Prefix:"
app.Use(session.Middleware(session.Options{
Name: "GSESSION",
Provider: &session.ProviderOptions{
Adapter: "redis",
Config: redisOptions,
},
}))
// router
app.Get("/", func(c *baa.Context) {
// get the session handler
session := c.Get("session").(*session.Session)
// get
session.Get("key")
// set
session.Set("key", "value")
// delete
session.Delete("key")
// destroy
session.Destroy()
})
// run app
app.Run(":1323")
}
session name
session id length, default is 16
provider options
provider adapter name, currently support redis
and memory
provider adapter config, each adapter has its own config
session cookie options
cookie domain, default is ''
cookie path, default is /
cookie life time, default is 0
, known as session cookie
garbage collection run interval, used for memory
adapter only
After this number of seconds, stored data will be seen as 'garbage' and cleaned up by the garbage collection process
Get inspirations from macaron session