Refactoring for Gin, NoSurf and SCS continues.
This commit is contained in:
25
internal/platform/session/session.go
Normal file
25
internal/platform/session/session.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"synlotto-website/internal/platform/config"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
)
|
||||
|
||||
func New(cfg config.Config) *scs.SessionManager {
|
||||
lifetime := 12 * time.Hour
|
||||
if d, err := time.ParseDuration(cfg.Session.Lifetime); err == nil && d > 0 {
|
||||
lifetime = d
|
||||
}
|
||||
|
||||
s := scs.New()
|
||||
s.Lifetime = lifetime
|
||||
s.Cookie.Name = cfg.Session.Name
|
||||
s.Cookie.HttpOnly = true
|
||||
s.Cookie.SameSite = http.SameSiteLaxMode
|
||||
s.Cookie.Secure = cfg.HttpServer.ProductionMode
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user