Documentation
¶
Overview ¶
Package sessionutils implements functionality to more easily deal with sessions for users. This wraps around gorilla/sessions to make code clearer and more usable.
Session data stores user authentication data in a cookie. The cookie value is encrypted and authenticated via gorilla/sessions.
Index ¶
- Variables
- func AddValue(session *sessions.Session, key string, value interface{})
- func Destroy(w http.ResponseWriter, r *http.Request)
- func ExtendExpiration(session *sessions.Session, w http.ResponseWriter, r *http.Request)
- func Get(r *http.Request) *sessions.Session
- func GetUserID(r *http.Request) int64
- func GetUsername(r *http.Request) string
- func Save(session *sessions.Session, w http.ResponseWriter, r *http.Request)
- func SetConfig(c config) error
Constants ¶
This section is empty.
Variables ¶
var Config = config{
SessionAuthKey: "",
SessionEncryptKey: "",
SessionLifetime: 7,
CookieDomain: "/",
}
Config is a copy of the config struct with some defaults set
Functions ¶
func AddValue ¶
AddValue adds a key value pair to a session don't forgot to save the session after adding values to it! this doesn't save automatically in case you are adding lots of new values to a session...b/c saving after every add would be pointless instead of just saving once
func Destroy ¶
func Destroy(w http.ResponseWriter, r *http.Request)
Destroy deletes a session for a request this logs a user out if they were logged in since middleware.Auth will no longer be able to validate the user
func ExtendExpiration ¶
ExtendExpiration pushes out the expiration of the session cookie to a further time this is done to keep a user logged in automatically if they use the app frequently
func Get ¶
Get gets an existing session for a request or creates a new session if none exists the field "IsNew" of the returned struct will be true if this session was just created
func GetUsername ¶
GetUsername gets the username we have stored in a session
Types ¶
This section is empty.