Add custom session
This commit is contained in:
25
internal/session/session.go
Normal file
25
internal/session/session.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"github.com/gorilla/sessions"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxAge = 86400 * 30
|
||||
IsProd = false
|
||||
)
|
||||
|
||||
func New() sessions.Store {
|
||||
key := os.Getenv("SESSION_SECRET")
|
||||
if key == "" {
|
||||
return nil
|
||||
}
|
||||
store := sessions.NewCookieStore([]byte(key))
|
||||
store.MaxAge(MaxAge)
|
||||
store.Options.Path = "/"
|
||||
store.Options.HttpOnly = true
|
||||
store.Options.Secure = IsProd
|
||||
|
||||
return store
|
||||
}
|
||||
Reference in New Issue
Block a user