wookie

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const WarrantTokenHeaderName = "Warrant-Token"

Variables

This section is empty.

Functions

func AddAsResponseHeader

func AddAsResponseHeader(w http.ResponseWriter, token *Token)

func ClientTokenMiddleware

func ClientTokenMiddleware(next http.Handler) http.Handler

Types

type ClientTokenKey

type ClientTokenKey struct{}

ClientToken context key

type Model

type Model interface {
	GetID() int64
	GetVersion() int64
	GetCreatedAt() time.Time
	ToToken() *Token
}

type MySQLRepository

type MySQLRepository struct {
	database.SQLRepository
}

func NewMySQLRepository

func NewMySQLRepository(db *database.MySQL) *MySQLRepository

func (MySQLRepository) Create

func (repo MySQLRepository) Create(ctx context.Context, version int64) (int64, error)

func (MySQLRepository) GetById

func (repo MySQLRepository) GetById(ctx context.Context, id int64) (Model, error)

func (MySQLRepository) GetLatest

func (repo MySQLRepository) GetLatest(ctx context.Context) (Model, error)

type PostgresRepository

type PostgresRepository struct {
	database.SQLRepository
}

func NewPostgresRepository

func NewPostgresRepository(db *database.Postgres) *PostgresRepository

func (PostgresRepository) Create

func (repo PostgresRepository) Create(ctx context.Context, version int64) (int64, error)

func (PostgresRepository) GetById

func (repo PostgresRepository) GetById(ctx context.Context, id int64) (Model, error)

func (PostgresRepository) GetLatest

func (repo PostgresRepository) GetLatest(ctx context.Context) (Model, error)

type SQLiteRepository

type SQLiteRepository struct {
	database.SQLRepository
}

func NewSQLiteRepository

func NewSQLiteRepository(db *database.SQLite) *SQLiteRepository

func (SQLiteRepository) Create

func (repo SQLiteRepository) Create(ctx context.Context, version int64) (int64, error)

func (SQLiteRepository) GetById

func (repo SQLiteRepository) GetById(ctx context.Context, id int64) (Model, error)

func (SQLiteRepository) GetLatest

func (repo SQLiteRepository) GetLatest(ctx context.Context) (Model, error)

type Token

type Token struct {
	ID        int64
	Version   int64
	Timestamp time.Time
}

func FromString

func FromString(wookieString string) (Token, error)

De-serialize token from string (from header)

func (Token) String

func (t Token) String() string

Get string representation of token (to set as header)

type Wookie

type Wookie struct {
	ID        int64     `mysql:"id" postgres:"id" sqlite:"id"`
	Version   int64     `mysql:"ver" postgres:"ver" sqlite:"ver"`
	CreatedAt time.Time `mysql:"createdAt" postgres:"created_at" sqlite:"createdAt"`
}

func (Wookie) GetCreatedAt

func (w Wookie) GetCreatedAt() time.Time

func (Wookie) GetID

func (w Wookie) GetID() int64

func (Wookie) GetVersion

func (w Wookie) GetVersion() int64

func (Wookie) ToToken

func (w Wookie) ToToken() *Token

type WookieRepository

type WookieRepository interface {
	Create(ctx context.Context, version int64) (int64, error)
	GetById(ctx context.Context, id int64) (Model, error)
	GetLatest(ctx context.Context) (Model, error)
}

func NewRepository

func NewRepository(db database.Database) (WookieRepository, error)

type WookieService

type WookieService struct {
	service.BaseService
	Repository WookieRepository
	Enabled    bool
}

func NewService

func NewService(env service.Env, repository WookieRepository, enabled bool) *WookieService

func (WookieService) WithWookieUpdate

func (svc WookieService) WithWookieUpdate(ctx context.Context, updateFunc func(txCtx context.Context) error) (*Token, error)

Apply given updateFunc() and create a new wookie for this update. Returns the new wookie token.

func (WookieService) WookieSafeRead

func (svc WookieService) WookieSafeRead(ctx context.Context, readFunc func(wkCtx context.Context) error) (*Token, error)

Jump to

Keyboard shortcuts

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