token

package
v0.0.0-...-89b6d9c Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: GPL-3.0 Imports: 6 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 (
	// KindFediInstance is a token that represents a federated social instance
	KindFediInstance Kind = 1 + iota
	// KindFediAccount is a token that represents a federated social account
	KindFediAccount
)

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() (*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