sessionutils

package
v4.0.0-release+incompa... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2018 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var Config = config{
	SessionAuthKey:    "",
	SessionEncryptKey: "",
	SessionLifetime:   7,
	CookieDomain:      "/",
}

Config is a copy of the config struct with some defaults set

Functions

func AddValue

func AddValue(session *sessions.Session, key string, value interface{})

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

func ExtendExpiration(session *sessions.Session, w http.ResponseWriter, r *http.Request)

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

func Get(r *http.Request) *sessions.Session

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 GetUserID

func GetUserID(r *http.Request) int64

GetUserID gets the user ID we have stored in a session

func GetUsername

func GetUsername(r *http.Request) string

GetUsername gets the username we have stored in a session

func Save

func Save(session *sessions.Session, w http.ResponseWriter, r *http.Request)

Save saves any new session data to an existing session write the new values to it (after using AddValue)

func SetConfig

func SetConfig(c config) error

SetConfig saves the configuration for the session store and starts the session store

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL