xuid

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

GoDoc

XUID

XUID is an ID that contains the exact same number of bits as a UUID, adds a type prefix, and is encoded in a string that will not be larger than 36 characters.

This is achieved by using base32 instead of base16. Base32 still only uses one set of alphabetic characters, allowing caseless matches.

Type

The type is a up to 5 characters long code that specifies what kind of object the ID is of. It is used to allow easy identification of an ID, either by humans or automated code.

Examples

  • UUID 3f1b4d37-34d9-46c6-b546-a57c5f736d22 with type shell becomes shell-h4nu2n-zu3f-dmnn-kguv-6f643nei
  • UUID 00000000-0000-0000-0000-000000000000 with type null becomes null-aaaaaa-aaaa-aaaa-aaaa-aaaaaaaa

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XUID

type XUID struct {
	Prefix string
	UUID   uuid.UUID
}

func FromKey added in v0.1.6

func FromKey(key string) (*XUID, error)

FromKey returns a fixed ID based on a given key that can be guaranteed to always have the same ID as long as the key is the same value. This can be used for a Util/Ref object that have fixed IDs for a given key.

func FromKeyPrefix added in v0.1.6

func FromKeyPrefix(key, prefix string) (*XUID, error)

FromKeyPrefix returns a fixed ID based on the key and prefix passed and is guaranteed to always return the same ID as long as the parameters are the same. This can be used for objects that need to keep the same ID no matter on which environment this runs.

func FromUUID

func FromUUID(u uuid.UUID, prefix string) (*XUID, error)

FromUUID returns a new xuid with the passed uuid and chosen prefix

func Must

func Must(x *XUID, err error) *XUID

Must can be used to transform any error thrown by the called method into a panic, and is useful when we know a call cannot fail, or that failure should be fatal.

func MustParse

func MustParse(s string) *XUID

func MustParseUUID

func MustParseUUID(inputUuid, prefix string) *XUID

func New

func New(prefix string) *XUID

New is a shorthand for Must(NewRandom(prefix)) and will always return a new xuid with the given prefix, or panic if for some reason the random generator does not work.

func NewRandom

func NewRandom(prefix string) (*XUID, error)

NewRandom returns a new random xuid with the given prefix set

func Parse

func Parse(s string) (*XUID, error)

func ParseUUID

func ParseUUID(inputUuid, prefix string) (*XUID, error)

func (XUID) Equals added in v0.1.5

func (x XUID) Equals(y XUID) bool

func (XUID) MarshalJSON added in v0.1.3

func (x XUID) MarshalJSON() ([]byte, error)

func (*XUID) Scan

func (x *XUID) Scan(value any) error

Scan sets the value of the XUID to the passed data, parsing it as needed.

func (XUID) String

func (x XUID) String() string

func (*XUID) ToUUID

func (x *XUID) ToUUID() string

func (*XUID) UnmarshalJSON added in v0.1.3

func (x *XUID) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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