session

package
v0.0.0-...-4347b6b Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DeviceIDUnknown = "unknown"

DeviceIDUnknown is the default for untracked devices.

Variables

View Source
var (
	ErrInvalidSession = errors.New("invalid session")
	ErrNotFound       = errors.New("session not found")
)

Common errors for Session service implementations and validations.

Functions

func IsInvalidSession

func IsInvalidSession(err error) bool

IsInvalidSession indicates if err is ErrInvalidSession.

Types

type Error

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

Error wraps common Session errors.

func (Error) Error

func (e Error) Error() string

type List

type List []*Session

List is a collection of sessions.

type Map

type Map map[string]*Session

Map is a session collection with their id as index.

type QueryOptions

type QueryOptions struct {
	DeviceIDs []string
	Enabled   *bool
	IDs       []string
	UserIDs   []uint64
}

QueryOptions is used to narrow-down session queries.

type Service

type Service interface {
	service.Lifecycle

	Put(namespace string, session *Session) (*Session, error)
	Query(namespace string, opts QueryOptions) (List, error)
}

Service for session interactions

func MemService

func MemService() Service

MemService returns a memory based Service implementation.

func PostgresService

func PostgresService(db *sqlx.DB) Service

PostgresService returns a Postgres based Service implementation.

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

ServiceMiddleware is a chainable behaviour modifier for Service.

func InstrumentMiddleware

func InstrumentMiddleware(
	component, store string,
	errCount kitmetrics.Counter,
	opCount kitmetrics.Counter,
	opLatency *prometheus.HistogramVec,
) ServiceMiddleware

InstrumentMiddleware observes key aspects of Service operations and exposes Prometheus metrics.

func LogMiddleware

func LogMiddleware(logger log.Logger, store string) ServiceMiddleware

LogMiddleware given a Logger wraps the next Service with logging capabilities.

type Session

type Session struct {
	CreatedAt time.Time
	DeviceID  string
	Enabled   bool
	ID        string
	UserID    uint64
}

Session attaches a session id to a user id.

func (*Session) Validate

func (s *Session) Validate() error

Validate performs semantic checks on the Session.

Jump to

Keyboard shortcuts

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