kefu/tools/session.go

25 lines
543 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 := "kefu"
var store sessions.Store
store = cookie.NewStore([]byte(sessionSecret))
store.Options(sessions.Options{
MaxAge: sessionMaxAge, //seconds
Path: "/",
})
return store
}