session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyKey           = "api_key"
	LoginTimeKey        = "login_time"
	LastActivityTimeKey = "last_activity_time"
	UserKey             = "user_id"
)

Session constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

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

Session holds user session information in memory.

func Load

func Load(ctx context.Context, id string) (*Session, error)

Load loads an existing Session object from the database.

The following errors are returned by this function: DBQueryFailure, SessionNotFound

func New

func New() *Session

New creates a new Session object.

func (*Session) End

func (s *Session) End(ctx context.Context) error

End ends and destroys the session.

func (*Session) GetInt

func (s *Session) GetInt(key string, def int) int

GetInt gets the value of the given key using the default value if the key does not exist or is not an int.

func (*Session) GetString

func (s *Session) GetString(key, def string) string

GetString gets the value of the given key using the default value if the key does not exist or is not a string.

func (*Session) ID

func (s *Session) ID() string

ID returns the session ID.

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns whether or not the session has expired.

func (*Session) Save

func (s *Session) Save(ctx context.Context) error

Save writes the session data to the database.

The following errors are returned by this function: GeneralFailure, DBInsertFailure, DBUpdateFailure

func (*Session) Set

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

Set sets the key to the given value.

Jump to

Keyboard shortcuts

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