jsonstore

package
v0.0.0-...-ecdd364 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encrypter

type Encrypter interface {
	Encrypt(data []byte) (encrypted []byte, err error)
	Decrypt(data []byte) (decrypted []byte, err error)
}

Encrypter represents a data encrypter.

type JSONSession

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

JSONSession contains session and encryption objects.

func NewJSONSession

func NewJSONSession(sd SessionStorer, encrypter Encrypter) (*JSONSession, error)

NewJSONSession returns a new JSONSession.

func (*JSONSession) All

func (s *JSONSession) All() (map[string][]byte, error)

All returns a map of all records.

func (*JSONSession) Commit

func (s *JSONSession) Commit(token string, b []byte, expiry time.Time) error

Commit adds a session token and data to the store with the given expiry time. If the session token already exists then the data and expiry time are updated.

func (*JSONSession) Delete

func (s *JSONSession) Delete(token string) error

Delete removes a session token and corresponding data from the store.

func (*JSONSession) Find

func (s *JSONSession) Find(token string) (b []byte, exists bool, err error)

Find returns the data for a given session token from the store. If the session token is not found or is expired, the returned exists flag will be set to false.

type SessionData

type SessionData struct {
	ID     string    `json:"id"`
	Data   []byte    `json:"data"`
	Expire time.Time `json:"expire"`
}

SessionData is a session record.

type SessionDatabase

type SessionDatabase struct {
	Records map[string]SessionData `json:"db"`
}

SessionDatabase contains all the session records.

func (*SessionDatabase) Load

func (sd *SessionDatabase) Load(ss SessionStorer, en Encrypter) error

Load all sessions.

func (*SessionDatabase) Save

func (sd *SessionDatabase) Save(ss SessionStorer, en Encrypter) error

Save all sessions.

type SessionStorer

type SessionStorer interface {
	Save([]byte) error
	Load() ([]byte, error)
}

SessionStorer reads and writes data to an object.

Jump to

Keyboard shortcuts

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