ggsession

package
v0.0.0-...-dd92ee3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ggsession will hold various useful data for Sessions.

Index

Constants

This section is empty.

Variables

Store is the session store.

Functions

func GetSession

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

GetSession returns the session with the open cookie file.

func MustBeAdmin

func MustBeAdmin(handler http.HandlerFunc) http.HandlerFunc

func MustBeAuthenticated

func MustBeAuthenticated(handler http.HandlerFunc) http.HandlerFunc

Types

type BasePageData

type BasePageData struct {
	Page          string
	Flashes       []Flash
	Authenticated bool
	IsAdmin       bool
}

BasePageData is the data that most pages will need. This can be used to build the data struct for templates.

func (*BasePageData) BasicData

func (data *BasePageData) BasicData(session SessionData)

BasicData fills in the BasePageData struct from the provided session.

type Flash

type Flash struct {
	Class   string
	Message string
}

Flash will be used to add flash messages to the session cookie. Class indicates the type of message, and will be used for CSS purposes. Message is the message itself.

Classes should be of the following values:

error: An Error messages success: Success that warents notification. info: Useful information that might not be overly important. Warning: Warning the user that they should procede carefuly.

type SessionData

type SessionData struct {
	Email         string
	Authenticated bool
	Flashes       []Flash
}

SessionData is a the struct to move data between the session cookie and the program.

func GetSessionData

func GetSessionData(session *sessions.Session) SessionData

GetSessionData grabs the SessionData struct from the cookie and returns it.

func NewSessionData

func NewSessionData() SessionData

NewSessionData returns a default SessionData struct.

func (*SessionData) AddFlash

func (sessionData *SessionData) AddFlash(class string, message string)

AddFlash adds a flash message to the SessionData object

func (*SessionData) GetFlashes

func (sessionData *SessionData) GetFlashes(clearData bool) []Flash

GetFlashes will add the flash messages from the SessionData struct t the PageData struct.

Jump to

Keyboard shortcuts

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