id

package module
v0.0.0-...-ad2ba2a Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 6 Imported by: 0

README

go-id

Package name: id

ULID from github.com/oklog/ulid is the blessed ID type.

Documentation

Overview

Package id aliases ULID from github.com/oklog/ulid as ID and provides some additional functions useful for IDs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero is a ID with all numbers zeroed.
	Zero = ulid.MustParseStrict("00000000000000000000000000")
)

Functions

func IsEmptyID

func IsEmptyID(id ID) bool

IsEmptyID returns true if id is 00000000000000000000000000.

Types

type ID

type ID = ulid.ULID

ID aliases ULID. While ULID could be used directly, using the alias avoids repeating the external dependency in all other packages.

func FromParts

func FromParts(time time.Time, rand uint64) (id ID, err error)

FromUint64 creates a ULID from an uint64.

The time parameter is used for the time part. It is converted to Unix timestamp of millisecond precision. The rand parameter is used for the random part. It is prepended with 2 zeroed bytes, since the random part is 10 byte long, but the integer is only 8 byte long.

func FromString

func FromString(str string) (ID, error)

FromString returns a ULID with the time part zeroed and the random part set to the 64 bit xxhash value of str.

func MustParse

func MustParse(id string) ID

MustParse parses an encoded ULID, panicking in case of failure. See ulid package on MustParseStrict for details. This function should only be used on safe strings.

func NewID

func NewID() ID

NewID is a convenience method for quickly creating a new ID without having to think about the parameters.

func Parse

func Parse(id string) (ID, error)

Parse parses an encoded ULID in strict manner. This function can be used on unsafe strings, as it returns an error.

Jump to

Keyboard shortcuts

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