Cloudreve/middleware/session.go

16 lines
449 B
Go
Raw Normal View History

2019-11-11 06:13:17 -05:00
package middleware
import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore"
2019-11-11 06:13:17 -05:00
"github.com/gin-gonic/gin"
)
// Session 初始化session
func Session(secret string) gin.HandlerFunc {
store := memstore.NewStore([]byte(secret))
2019-11-11 06:13:17 -05:00
//Also set Secure: true if using SSL, you should though
store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"})
return sessions.Sessions("cloudreve-session", store)
}