session

package
v0.0.0-...-cc0b965 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CtxKey

type CtxKey struct{}

CtxKey is the key to use when storing session in a Context

type Session

type Session struct {
	UserID           int       // Our User ID
	GitHubID         int       // User's GitHub ID
	GitHubOAuthState uuid.UUID // State/CSRF token when using GitHub OAuth flow
	// contains filtered or unexported fields
}

Session represents a user's session and contains all their data. This is marshalled into a []byte storage using json, so some restrictions such as only exported members are saved apply.

func FromContext

func FromContext(ctx context.Context) *Session

FromContext returns the session from a context.

func GetOrCreate

func GetOrCreate(db *sql.DB, w http.ResponseWriter, r *http.Request) (*Session, error)

GetOrCreate reads the http.Request looking for a session ID and attempts to load this sesstion from the database. Most errors are handled by creating a new session. Call Save() on the session to persist to db.

func (*Session) Delete

func (s *Session) Delete(w http.ResponseWriter) error

Delete deletes the user's sessions from the database and sets the cookie to expire.

func (*Session) LoggedIn

func (s *Session) LoggedIn() bool

LoggedIn checks if the user is currently logged in.

func (*Session) Save

func (s *Session) Save() error

Save saves the session to the database.

Jump to

Keyboard shortcuts

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