base62

package
v0.0.0-...-2083224 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Base62 is a string respresentation of every possible base62 character
	Base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

	// MaxTokenLength is the largest possible character length of a token
	MaxTokenLength = 10

	// MinTokenLength is the smallest possible character length of a token
	MinTokenLength = 1

	// DefaultTokenLength is the default size of a token
	DefaultTokenLength = 8
)
View Source
const (
	// ErrTokenTooSmall is the error returned or panic'd when a base62 token is smaller than `MinTokenLength`
	ErrTokenTooSmall = Error("the base62 token is smaller than MinTokenLength")

	// ErrTokenTooBig is the error returned or panic'd when a base62 token is larger than `MaxTokenLength`
	ErrTokenTooBig = Error("the base62 token is larger than MaxTokenLength")

	// ErrInvalidCharacter is the error returned or panic'd when a non `Base62` string is being parsed
	ErrInvalidCharacter = Error("there was a non base62 character in the token")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error is a token error

func (Error) Error

func (e Error) Error() string

Error implements the `errors.Error` interface

type Token

type Token uint64

Token is an alias of an uint64 that is marshalled into a base62 encoded token

func Decode

func Decode(token string) (Token, error)

Decode returns a token from a 1-12 character base62 encoded string

func New

func New(tokenLength ...int) Token

New returns a `Base62` encoded `Token` of *up to* `DefaultTokenLength` if you pass in a `tokenLength` between `MinTokenLength` and `MaxTokenLength` this will return a `Token` of *up to* that length instead if you pass in a `tokenLength` that is out of range it will panic

func (Token) Encode

func (t Token) Encode() string

Encode encodes the token into a base62 string

func (Token) MarshalText

func (t Token) MarshalText() ([]byte, error)

MarshalText implements the `encoding.TextMarsheler` interface

func (*Token) UnmarshalText

func (t *Token) UnmarshalText(data []byte) error

UnmarshalText implements the `encoding.TextUnmarshaler` interface

Jump to

Keyboard shortcuts

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