ulids

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownType = errors.New("cannot parse ulid input: unknown type")
	ErrMissingID   = errors.New("id required for this resource")
	ErrIDMismatch  = errors.New("resource id does not match target")
)
View Source
var Null = ulid.ULID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

Null ULID pre-allocated for easier checking.

Functions

func CheckIDMatch

func CheckIDMatch(id, target ulid.ULID) error

CheckIDMatch returns an error if the id is Null or it does not match the target.

func IsZero

func IsZero(uid ulid.ULID) bool

Determines if the specified uid is the Null or zero-valued ULID. Useful for determining if a ULID has been passed into a method or is valid.

func MustParse

func MustParse(uid any) (id ulid.ULID)

MustParse parses the ULID but panics on errors.

func New

func New() ulid.ULID

New creates a new montonically increasing ULID in a threadsafe manner using a cryptographically random source of entropy for security (e.g. to ensure that an attacker cannot guess the next ULID to be generated). If the ULID cannot be generated this method panics rather than returning an error.

func Parse

func Parse(uid any) (ulid.ULID, error)

Parse a ULID from a string or a []byte (or return a ulid.ULID). This method makes it easier to convert any user-specified type into a ULID.

Types

type NullULID

type NullULID struct {
	ULID  ulid.ULID
	Valid bool
}

func (NullULID) MarshalBinary

func (nu NullULID) MarshalBinary() ([]byte, error)

func (*NullULID) MarshalJSON

func (nu *NullULID) MarshalJSON() ([]byte, error)

func (*NullULID) MarshalText

func (nu *NullULID) MarshalText() ([]byte, error)

func (*NullULID) Scan

func (nu *NullULID) Scan(value interface{}) error

func (*NullULID) UnmarshalBinary

func (nu *NullULID) UnmarshalBinary(data []byte) error

func (*NullULID) UnmarshalJSON

func (nu *NullULID) UnmarshalJSON(data []byte) error

func (*NullULID) UnmarshalText

func (nu *NullULID) UnmarshalText(data []byte) error

func (NullULID) Value

func (nu NullULID) Value() (driver.Value, error)

type PoolEntropy

type PoolEntropy struct {
	sync.Pool
}

PoolEntropy is a thread-safe source of entropy that is not cryptographically secure but provides fast, concurrent access to random data generation.

func NewPool

func NewPool() *PoolEntropy

func (*PoolEntropy) Read

func (e *PoolEntropy) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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