token

package
v0.0.0-...-0f594a8 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is returned when a token's data is an invalid length.
	ErrInvalidLength = errors.New("invalid length")
	// ErrSaltEmpty is returned when a token's data is an invalid length.
	ErrSaltEmpty = errors.New("salt empty")
)

Functions

This section is empty.

Types

type Kind

type Kind int64

Kind represents the kind of model to encode a token for.

const (
	// KindInstance is a token that represents an instance.
	KindInstance Kind = 1 + iota
	// KindAccount is a token that represents an account.
	KindAccount
	// KindTag is a token that represents a tag.
	KindTag
)

This order can not change else all external urls with tokens will become invalid.

func (Kind) String

func (k Kind) String() string

type Tokenizer

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

Tokenizer generates public tokens for database IDs to obfuscate the database IDs.

func New

func New(salt string) (*Tokenizer, error)

New returns a new tokenizer.

func (*Tokenizer) DecodeToken

func (t *Tokenizer) DecodeToken(token string) (Kind, int64, error)

DecodeToken returns the kind and id number of a provided token.

func (*Tokenizer) EncodeToken

func (t *Tokenizer) EncodeToken(kind Kind, id int64) (string, error)

EncodeToken turns a model kind and id into a token.

func (*Tokenizer) GetToken

func (t *Tokenizer) GetToken(o interface{}) string

GetToken returns a token for a known model type.

Jump to

Keyboard shortcuts

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