You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
542 B
24 lines
542 B
package server |
|
|
|
import ( |
|
"github.com/gin-contrib/sessions" |
|
"github.com/gin-contrib/sessions/cookie" |
|
"github.com/gin-gonic/gin" |
|
) |
|
|
|
// SessionStore 中间件,处理 session |
|
func SessionStore(keyPairs string) gin.HandlerFunc { |
|
store := sessionConfig() |
|
return sessions.Sessions(keyPairs, store) |
|
} |
|
|
|
func sessionConfig() sessions.Store { |
|
sessionMaxAge := 3600 |
|
sessionSecret := "golang-tech-stack" |
|
store := cookie.NewStore([]byte(sessionSecret)) |
|
store.Options(sessions.Options{ |
|
MaxAge: sessionMaxAge, |
|
Path: "/", |
|
}) |
|
return store |
|
}
|
|
|