Documentation ¶
Index ¶
- Variables
- func TestManager(t *testing.T, newRepo func() ReadWriter)
- type Data
- type JSONMemoryRepo
- type Manager
- func (m *Manager) Clear(ctx context.Context)
- func (m *Manager) Commit(ctx context.Context) (string, error)
- func (m *Manager) Delete(ctx context.Context, key string)
- func (m *Manager) Destroy(ctx context.Context)
- func (m *Manager) Get(ctx context.Context, key string) any
- func (m *Manager) GetBool(ctx context.Context, key string) bool
- func (m *Manager) GetFloat32(ctx context.Context, key string) float32
- func (m *Manager) GetFloat64(ctx context.Context, key string) float64
- func (m *Manager) GetInt(ctx context.Context, key string) int
- func (m *Manager) GetString(ctx context.Context, key string) string
- func (m *Manager) GetStrings(ctx context.Context, key string) []string
- func (m *Manager) GetTime(ctx context.Context, key string) time.Time
- func (m *Manager) Has(ctx context.Context, key string) bool
- func (m *Manager) Load(ctx context.Context, id string) (context.Context, error)
- func (m *Manager) PopBool(ctx context.Context, key string) bool
- func (m *Manager) PopFloat32(ctx context.Context, key string) float32
- func (m *Manager) PopFloat64(ctx context.Context, key string) float64
- func (m *Manager) PopInt(ctx context.Context, key string) int
- func (m *Manager) PopString(ctx context.Context, key string) string
- func (m *Manager) PopStrings(ctx context.Context, key string) []string
- func (m *Manager) PopTime(ctx context.Context, key string) time.Time
- func (m *Manager) Renew(ctx context.Context) error
- func (m *Manager) Set(ctx context.Context, key string, value any)
- func (m *Manager) Status(ctx context.Context) Status
- type ReadWriter
- type Reader
- type Session
- type Status
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func TestManager ¶
func TestManager(t *testing.T, newRepo func() ReadWriter)
Types ¶
type JSONMemoryRepo ¶
type JSONMemoryRepo struct {
// contains filtered or unexported fields
}
JSONMemoryRepo implements an in-memory repo for use with a session manager. The intended use of this repo is developer tests.
We want to test against JSON here to make sure we handle numbers correctly, which is why we map to a byte slice
func NewJSONMemoryRepo ¶
func NewJSONMemoryRepo(useNumber bool) *JSONMemoryRepo
NewJSONMemoryRepo returns a new in-memory session repo, intended for use in developer tests.
func (*JSONMemoryRepo) DestroySession ¶
func (r *JSONMemoryRepo) DestroySession(ctx context.Context, id string) error
Destroy deletes a session by the given id from memory.
func (*JSONMemoryRepo) FindSessionDataByID ¶
FindByID attempts to find session data using the given id.
func (*JSONMemoryRepo) SaveSession ¶
func (r *JSONMemoryRepo) SaveSession(ctx context.Context, s Session) error
Save persists the given session in-memory.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager loads, creates, and commits session data via contexts.
func NewManager ¶
func NewManager(repo ReadWriter) *Manager
NewManager creates a new session manager that will use the provided repository to interact with session data.
func (*Manager) Commit ¶
Commit uses the given context to save and/or destroy session data. Until Commit is called all session data only exists on a context.
func (*Manager) Delete ¶
Delete will delete the session value at the given key. Deleting data will also set the session's status to modified.
func (*Manager) Destroy ¶
Destroy sets the status of the session on the given context to destroyed. Any persisted session data is not actually destroyed until any changes have been committed.
func (*Manager) Get ¶
Get will fetch the session value for the given key. If the key does not exist then the zero value is returned. Fetching data will set the session's status to accessed.
func (*Manager) GetBool ¶
GetBool fetches a bool from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetFloat32 ¶
GetFloat32 fetches a float32 from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetFloat64 ¶
GetFloat64 fetches a float64 from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetInt ¶
GetInt fetches a int from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetString ¶
GetString fetches a string from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetStrings ¶
GetString fetches a string slice from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) GetTime ¶
GetTime fetches a time.Time from the session's data. If the given key does not exist then the zero value is returned.
func (*Manager) Load ¶
Load attempts to load a session using the given id into the given context.
If a session with the provided id is not found then a new session is created with a new id.
After a session has been loaded or created it is set on the returned context.
func (*Manager) PopBool ¶
PopBool fetches a bool from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopFloat32 ¶
PopFloat32 fetches a float32 from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopFloat64 ¶
PopFloat64 fetches a float64 from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopInt ¶
PopInt fetches a int from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopString ¶
PopString fetches a string from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopStrings ¶
PopString fetches a string slice from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) PopTime ¶
PopTime fetches a time.Time from the session's data. After fetching the value it is then deleted from the session. If the given key does not exist then the zero value is returned.
func (*Manager) Renew ¶
Renew will update the id of the session on the given context. It will also track the original session id so it can be destroyed when session data is committed. Renewing a session's id will also set the session's status to modified.
type ReadWriter ¶
ReadWriter is the combination of the Reader and Writer interfaces.