session

package
v0.0.0-...-6cdf0ab Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(ctx context.Context)

Clear removes all the values from the session store. It does not remove the session token itself (the Cookie for example). To remove the token also, call Reset() in addition to Clear()

func ClearRoutes

func ClearRoutes(ctx context.Context)

ClearRoutes removes all routes from the route stack

func ClearStack

func ClearStack(ctx context.Context, stack string)

ClearStack clears the named stack

func Get

func Get(ctx context.Context, key string) (v interface{})

Get returns an interface value stored at the given key. nil is returned if nothing is there.

func GetBool

func GetBool(ctx context.Context, key string) (v bool)

GetBool returns the boolean at the given key in the session store. If the key does not exist OR if what does exist at that key is not a boolean, false will be returned.

func GetFloat32

func GetFloat32(ctx context.Context, key string) (v float32)

GetFloat32 returns the float32 at the given key in the session store. If the key does not exist OR if what does exist at that key is not a float, 0 will be returned.

func GetFloat64

func GetFloat64(ctx context.Context, key string) (v float64)

GetFloat64 returns the float64 at the given key in the session store. If the key does not exist OR if what does exist at that key is not a float, 0 will be returned.

func GetInt

func GetInt(ctx context.Context, key string) (v int)

GetInt returns the integer at the given key in the session store. If the key does not exist OR if what does exists at that key is not an integer, zero will be returned. Call Has() if the zero value has meaning for you and you want to check for existence.

func GetString

func GetString(ctx context.Context, key string) (v string)

GetString returns the string at the given key in the session store. If the key does not exist OR if what does exist at that key is not a string, an empty string will be returned.

func Has

func Has(ctx context.Context, key string) bool

Has returns true if the given key exists in the session store

func HasSession

func HasSession(ctx context.Context) bool

HasSession returns true if the session exists.

func PopRoute

func PopRoute(ctx context.Context) (loc string)

PopRoute pops the given route off of the route stack and returns it.

func PopStack

func PopStack(ctx context.Context, stack string) (value string)

PopStack pops the given value off of the named stack and returns it.

func PushRoute

func PushRoute(ctx context.Context, loc string)

PushRoute pushes the given route onto the route stack.

func PushStack

func PushStack(ctx context.Context, stack string, value string)

PushStack pushes the given value onto the given named stack in the session. The name becomes a variable in the current session. The value must be JsonSerializable.

func Remove

func Remove(ctx context.Context, key string)

Remove will remove the value at the given key in the session store.

func Reset

func Reset(ctx context.Context)

Reset will destroy the old session token. If you also call Clear, or don't have any session data after processing the request, it will remove the session token all together after the request. If you do have session data, this will cause the session data to be moved to a new session token.

func Set

func Set(ctx context.Context, key string, v interface{})

Set will put the value at the given key in the session store. v must be serializable

func SetBool

func SetBool(ctx context.Context, key string, v bool)

SetBool will put the bool value at the given key in the session store.

func SetFloat32

func SetFloat32(ctx context.Context, key string, v float32)

SetFloat32 will put the float32 value at the given key in the session store.

func SetFloat64

func SetFloat64(ctx context.Context, key string, v float64)

SetFloat64 will put the float64 value at the given key in the session store.

func SetInt

func SetInt(ctx context.Context, key string, v int)

SetInt will put the int value at the given key in the session store.

func SetString

func SetString(ctx context.Context, key string, v string)

SetString will put the string value at the given key in the session store.

Types

type ManagerI

type ManagerI interface {
	Use(http.Handler) http.Handler
}

ManagerI is the interface for session managers.

func NewScsManager

func NewScsManager(mgr *scs.SessionManager) ManagerI

type Mock

type Mock struct {
}

func NewMock

func NewMock() *Mock

func (Mock) Use

func (mgr Mock) Use(next http.Handler) http.Handler

func (Mock) With

func (mgr Mock) With(ctx context.Context) context.Context

With inserts the mock session into the current session

type ScsManager

type ScsManager struct {
	*scs.SessionManager
}

ScsManager implements the ManagerI interface for the github.com/alexedwards/scs session manager.

Note that this manager does post-processing on the response writer, including writing headers. It therefore relies on the buffered output handler to collect the output before writing the headers.

func (ScsManager) Use

func (mgr ScsManager) Use(next http.Handler) http.Handler

Use is an http handler that wraps the session management process. It will get and put session data into the http context.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is the object that is stored in the context. (Actually a pointer to that object). You normally do not work with the Session object, but instead should call session.GetInt, session.SetInt, etc. Session is exported so that it can be created by custom session managers.

func NewSession

func NewSession() *Session

NewSession creates a new session object for use by session managers. You should not normally need to call this. To reset the session data, call Reset()

func (*Session) MarshalBinary

func (s *Session) MarshalBinary() ([]byte, error)

MarshalBinary serializes the session data for storage.

func (*Session) UnmarshalBinary

func (s *Session) UnmarshalBinary(data []byte) error

UnmarshalBinary unserializes saved session data

Directories

Path Synopsis
Package location implements a location queue built on top of the session service.
Package location implements a location queue built on top of the session service.

Jump to

Keyboard shortcuts

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