token

package module
v0.0.0-...-d07696b Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2015 License: MIT Imports: 4 Imported by: 0

README

go-token Image of build

Redis based token generator

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIdNotSet     = errors.New("id is not set")
	ErrValueNotSet  = errors.New("token value is not set")
	ErrNotFound     = errors.New("not found")
	ErrInvalidToken = errors.New("invalid token")
)

Functions

This section is empty.

Types

type Token

type Token struct {
	// unique id for token owner
	Id string

	// token value
	Value string

	// expiration time
	ExpireAt time.Time
}

func NewToken

func NewToken() *Token

type TokenManager

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

func NewTokenManager

func NewTokenManager(redisConn *redis.Redis, ttl time.Duration) *TokenManager

func (*TokenManager) Authenticate

func (tm *TokenManager) Authenticate(t *Token) error

Authenticate checks if token is valid for the given account

func (*TokenManager) Create

func (tm *TokenManager) Create(id string) (*Token, error)

Create creates a token with a random uuid and TTL. It is not idempotent, therefore with every call, it regenerates the token for id

func (*TokenManager) Get

func (tm *TokenManager) Get(id string) (*Token, error)

func (*TokenManager) GetOrCreate

func (tm *TokenManager) GetOrCreate(id string) (*Token, error)

GetOrCreate gets token of the given account, and creates if it does not exist

func (*TokenManager) Invalidate

func (tm *TokenManager) Invalidate(id string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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