package tools import ( "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" "github.com/gin-gonic/gin" ) // 中间件,处理session func Session(keyPairs string) gin.HandlerFunc { store := SessionConfig() return sessions.Sessions(keyPairs, store) } func SessionConfig() sessions.Store { sessionMaxAge := 3600 sessionSecret := "gofly" var store sessions.Store store = cookie.NewStore([]byte(sessionSecret)) store.Options(sessions.Options{ MaxAge: sessionMaxAge, //seconds Path: "/", }) return store }