尽管 README 文档很少,但GoDoc 文档对此更清楚一些。
请注意,gin-gonic 会话包在下面使用gorilla/sessions并共享相同的选项 API。
// We check for errors.
store, err := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("secret"))
if err != nil {
// Handle the error. Probably bail out if we can't connect.
}
// Ref: https://godoc.org/github.com/gin-gonic/contrib/sessions#Options
store.Options = &sessions.Options{
MaxAge: 86400,
Path: "/",
Secure: true,
HttpOnly: true,
}
// Use the store once configured.
router.Use(sessions.Sessions("workino_session", store))