19 lines
365 B
Go
19 lines
365 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/alexedwards/scs/v2"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Session(sm *scs.SessionManager) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
handler := sm.LoadAndSave(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
c.Request = r
|
|
c.Next()
|
|
}))
|
|
handler.ServeHTTP(c.Writer, c.Request)
|
|
}
|
|
}
|