utilities for gorilla/sessions
go get github.com/tomocy/sensei
Create a Sensei
instance with sessions.Store
and session key
var manager = sensei.New(store, sessionKey)
var store = sessions.NewCookieStore(
securecookie.GenerateRandomKey(64),
securecookie.GenerateRandomKey(32),
)
const sessionKey = "BananaIsIncludedIntoSnacks"
func KeepAuthenticUserID(w http.ResponseWriter, r *http.Request, id string) error {
return manager.Set(w, r, authenticUserID, id)
}
func FindAuthenticUserID(r *http.Request) (string, error) {
if id, ok := manager.Get(r, authenticUserID); ok && id != "" {
return id, nil
}
return "", errors.New("no authentic user id")
}
const (
authentiUserID = "authentic_user_id"
)