16 lines
445 B
Go
16 lines
445 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-contrib/sessions"
|
||
|
"github.com/gin-contrib/sessions/cookie"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
// Session 初始化session
|
||
|
func Session(secret string) gin.HandlerFunc {
|
||
|
store := cookie.NewStore([]byte(secret))
|
||
|
//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)
|
||
|
}
|