ulid

package module
v0.0.0-...-71154c7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

README

go-ulid

golang implimentation of ulid/javascript

warning

This is as close of a clone of the origninal code base as I could achieve, so some functions may end up being optimized later.

Documentation

Index

Constants

View Source
const B32_CHARACTERS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
View Source
const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" // Crockford's Base32
View Source
const ENCODING_LEN = 32 // from ENCODING.length;
View Source
const MAX_ULID = "7ZZZZZZZZZZZZZZZZZZZZZZZZZ"
View Source
const MIN_ULID = "00000000000000000000000000"
View Source
const RANDOM_LEN = 16
View Source
const TIME_LEN = 10
View Source
const TIME_MAX int64 = 281474976710655 // from Math.pow(2, 48) - 1;

Variables

View Source
var ErrBase32IncorrectEncoding = errors.New("B32_ENC_INVALID")
View Source
var ErrDecodeTimeInvalidCharacter = errors.New("DEC_TIME_CHAR")
View Source
var ErrDecodeTimeValueMalformed = errors.New("DEC_TIME_MALFORMED")
View Source
var ErrEncodeTimeNegative = errors.New("ENC_TIME_NEG")
View Source
var ErrEncodeTimeSizeExceeded = errors.New("ENC_TIME_SIZE_EXCEED")
View Source
var ErrEncodeTimeValueMalformed = errors.New("ENC_TIME_MALFORMED")
View Source
var ErrPRNGDetectFailure = errors.New("PRNG_DETECT")
View Source
var ErrULIDInvalid = errors.New("ULID_INVALID")
View Source
var ErrUUIDInvalid = errors.New("UUID_INVALID")
View Source
var ErrUnexpected = errors.New("UNEXPECTED")
View Source
var REGEX = regexp.MustCompile("^[0-7][0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z]{25}$")
View Source
var UUID_REGEX = regexp.MustCompile("^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$")

Functions

func DecodeTime

func DecodeTime(id ULID) (int64, error)

func EncodeRandom

func EncodeRandom(length int, rng PRNG) (string, error)

func EncodeTime

func EncodeTime(unix int64) (string, error)

func FixULIDBase32

func FixULIDBase32(input string) string

func FromUUID

func FromUUID(uuid string) (string, error)

func IsValid

func IsValid(id string) bool

Types

type Factory

type Factory interface {
	NextSeeded(seed int64) (ULID, error)
	Next() (ULID, error)
}

func NewFactory

func NewFactory(maybe_rng_override ...PRNG) Factory

type PRNG

type PRNG func() (int64, error)

type ULID

type ULID string

func Next

func Next(seed int64, rng PRNG) (ULID, error)

type UUID

type UUID string

type Factory func(int64) ULID

func ToUUID

func ToUUID(ulid ULID) (UUID, error)

Jump to

Keyboard shortcuts

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