session

package
v0.0.0-...-689a9a2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSessionDeathCallback

func AddSessionDeathCallback(fn func(string))

AddSessionDeathCallback adds a function to the list of function to be called when a session dies. The key of the session is passed the function to identify the dying session in other data structures.

func Chain

func Chain(mw ...func(http.Handler) http.Handler) http.Handler

Chain is a bootstrapping mechanism to wrap the results of given middleware constructors around each other to build a fully decorated middleware which chains them all.

func Checking

func Checking(check func(*Session) bool, code int) func(http.Handler) http.Handler

Checking is a middleware constructor which checks the session with a given test. When the test passed the inner handler is called. Otherwise the chain excecution is terminated with given HTTP code.

func LoggedIn

func LoggedIn(s *Session) bool

LoggedIn is a session test function which checks if the session is associated with user.

func Logging

func Logging(next http.Handler) http.Handler

Logging is a middleware to write the called endpoint and the HTTP method to the log.

func Not

func Not(fn func(*Session) bool) func(*Session) bool

Not simply negates a given session test function.

func Sessioned

func Sessioned(next http.Handler) http.Handler

Sessioned generates a middleware which attributes a handler with a cookie based session.

func Term

func Term(f func(http.ResponseWriter, *http.Request)) func(http.Handler) http.Handler

Term is a middleware constructor which simple generates a handler which calls the final endpoint.

Types

type Session

type Session struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Session encapsulates the session state,

func FromContext

func FromContext(ctx context.Context) (*Session, bool)

FromContext extracts a session from a given context.

func NewSession

func NewSession(key string) *Session

NewSession creates a new session with a given key.

func (*Session) Del

func (s *Session) Del(key string)

Del deletes the value of a given key from the session.

func (*Session) Get

func (s *Session) Get(key string) (interface{}, bool)

Get returns the value associated with the given key. The second return value indicates if the value was found.

func (*Session) GetUser

func (s *Session) GetUser() (user int64, valid bool)

GetUser returns the ID of the user associated with the session. The second return value is false if there is no user bound to the session.

func (*Session) Invalid

func (s *Session) Invalid() (value bool)

Invalid returns true if the session is invalid.

func (*Session) Invalidate

func (s *Session) Invalidate()

Invalidate marks a session as invalid.

func (*Session) Key

func (s *Session) Key() string

Key returns the session key.

func (*Session) Logout

func (s *Session) Logout()

Logout does a logout of the session so there is no longer a user attached to it.

func (*Session) Persist

func (s *Session) Persist() bool

Persist writes the session to the backend or deletes it from the infrastructure if its invalid.

func (*Session) Put

func (s *Session) Put(key string, value interface{})

Put stores a given value under a given key in the session.

func (*Session) SetUser

func (s *Session) SetUser(value int64)

SetUser binds the user by a given ID to the session.

Jump to

Keyboard shortcuts

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