36 lines
728 B
Go
36 lines
728 B
Go
package session
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"net/http"
|
|
"time"
|
|
|
|
"synlotto-website/internal/platform/config"
|
|
|
|
"github.com/alexedwards/scs/v2"
|
|
)
|
|
|
|
func New(cfg config.Config) *scs.SessionManager {
|
|
gob.Register(time.Time{})
|
|
s := scs.New()
|
|
|
|
// Lifetime (absolute max age)
|
|
if d, err := time.ParseDuration(cfg.Session.Lifetime); err == nil && d > 0 {
|
|
s.Lifetime = d
|
|
} else {
|
|
s.Lifetime = 12 * time.Hour
|
|
}
|
|
|
|
// Idle timeout (expire after inactivity)
|
|
if d, err := time.ParseDuration(cfg.Session.IdleTimeout); err == nil && d > 0 {
|
|
s.IdleTimeout = d
|
|
}
|
|
|
|
s.Cookie.Name = cfg.Session.CookieName
|
|
s.Cookie.HttpOnly = true
|
|
s.Cookie.SameSite = http.SameSiteLaxMode
|
|
s.Cookie.Secure = cfg.HttpServer.ProductionMode
|
|
|
|
return s
|
|
}
|