24 lines
431 B
Go
24 lines
431 B
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/sessions"
|
|
)
|
|
|
|
var (
|
|
SessionStore *sessions.CookieStore
|
|
Name string
|
|
)
|
|
|
|
func GetSession(w http.ResponseWriter, r *http.Request) (*sessions.Session, error) {
|
|
if SessionStore == nil {
|
|
return nil, fmt.Errorf("session store not initialized")
|
|
}
|
|
if Name == "" {
|
|
return nil, fmt.Errorf("session name not configured")
|
|
}
|
|
return SessionStore.Get(r, Name)
|
|
}
|