Documentation
¶
Index ¶
- Constants
- Variables
- type PULID
- func Make(prefix string) PULID
- func MustNew(prefix string, ms uint64, entropy io.Reader) PULID
- func MustNewDefault(prefix string, t time.Time) PULID
- func MustParse(id string) PULID
- func MustParseStrict(id string) PULID
- func New(prefix string, ms uint64, entropy io.Reader) (PULID, error)
- func Parse(id string) (PULID, error)
- func ParseStrict(id string) (PULID, error)
- func (id PULID) Bytes() []byte
- func (id PULID) Compare(other PULID) int
- func (id PULID) Entropy() []byte
- func (id PULID) MarshalBinary() ([]byte, error)
- func (id PULID) MarshalBinaryTo(dst []byte) error
- func (id PULID) MarshalGQL(w io.Writer)
- func (id PULID) MarshalText() ([]byte, error)
- func (id PULID) MarshalTextTo(dst []byte) error
- func (id PULID) Prefix() string
- func (id PULID) PrefixBytes() []byte
- func (id *PULID) Scan(src interface{}) error
- func (id *PULID) SetEntropy(e []byte) error
- func (id *PULID) SetTime(ms uint64) error
- func (id PULID) String() string
- func (id PULID) Time() uint64
- func (id PULID) Timestamp() time.Time
- func (id PULID) ULID() ulid.ULID
- func (id *PULID) UnmarshalBinary(data []byte) error
- func (id *PULID) UnmarshalGQL(v interface{}) error
- func (id *PULID) UnmarshalText(v []byte) error
- func (id PULID) Value() (driver.Value, error)
Constants ¶
const EncodedSize = 28
Variables ¶
var ( ErrPrefixLength = errors.New("pulid: bad prefix length") Nil = PULID{} )
Functions ¶
This section is empty.
Types ¶
type PULID ¶
type PULID [18]byte
PULID implements a PULID - a prefixed ULID.
func Make ¶
Make returns a PULID with the current time in Unix milliseconds and monotonically increasing entropy for the same millisecond. It is safe for concurrent use, leveraging a sync.Pool underneath for minimal contention. Panic if prefix is not of length 2.
func MustNew ¶
MustNew is a convenience function equivalent to New that panics on failure instead of returning an error.
func MustNewDefault ¶
MustNewDefault is a convenience function equivalent to MustNew with DefaultEntropy as the entropy. It may panic if the given time.Time is too large or too small. Also panic if prefix is not of length 2.
func MustParse ¶
MustParse is a convenience function equivalent to Parse that panics on failure instead of returning an error.
func MustParseStrict ¶
MustParseStrict is a convenience function equivalent to ParseStrict that panics on failure instead of returning an error.
func New ¶
New returns a PULID with the given Unix milliseconds timestamp and an optional entropy source. Use the Timestamp function to convert a time.Time to Unix milliseconds.
ErrPrefixLength is returned when passing a prefix bigger or smaller than 2.
ErrBigTime is returned when passing a timestamp bigger than MaxTime. Reading from the entropy source may also return an error.
Safety for concurrent use is only dependent on the safety of the entropy source.
func Parse ¶
Parse parses an encoded PULID, returning an error in case of failure.
ErrDataSize is returned if the len(ulid) is different from an encoded ULID's length. Invalid encodings produce undefined ULIDs. For a version that returns an error instead, see ParseStrict.
func ParseStrict ¶
ParseStrict parses an encoded PULID, returning an error in case of failure.
It is like Parse, but additionally validates that the parsed ULID consists only of valid base32 characters. It is slightly slower than Parse.
ErrDataSize is returned if the len(ulid) is different from an encoded ULID's length. Invalid encodings return ErrInvalidCharacters.
func (PULID) Compare ¶
Compare returns an integer comparing id and other lexicographically. The result will be 0 if id==other, -1 if id < other, and +1 if id > other.
func (PULID) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface by returning the ULID as a byte slice.
func (PULID) MarshalBinaryTo ¶
MarshalBinaryTo writes the binary encoding of the ULID to the given buffer. ErrBufferSize is returned when the len(dst) != 16.
func (PULID) MarshalGQL ¶
MarshalGQL implements the graphql.Marshaler interface
func (PULID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface by returning the string encoded ULID.
func (PULID) MarshalTextTo ¶
MarshalTextTo writes the ULID as a string to the given buffer. ErrBufferSize is returned when the len(dst) != 26.
func (*PULID) Scan ¶
Scan implements the sql.Scanner interface. It supports scanning a string or byte slice.
func (*PULID) SetEntropy ¶
SetEntropy sets the ULID entropy to the passed byte slice. ErrDataSize is returned if len(e) != 10.
func (*PULID) SetTime ¶
SetTime sets the time component of the ULID to the given Unix time in milliseconds.
func (PULID) String ¶
String returns a lexicographically sortable string encoded PULID (26 characters, non-standard base 32) e.g. PR01AN4Z07BY79KA1307SR9X4MV3. Format: pptttttttttteeeeeeeeeeeeeeee where p is prefix t is time and e is entropy.
func (PULID) Time ¶
Time returns the Unix time in milliseconds encoded in the ULID. Use the top level Time function to convert the returned value to a time.Time.
func (*PULID) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface by copying the passed data and converting it to a ULID. ErrDataSize is returned if the data length is different from ULID length.
func (*PULID) UnmarshalGQL ¶
UnmarshalGQL implements the graphql.Unmarshaler interface
func (*PULID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface by parsing the data as string encoded ULID.
ErrDataSize is returned if the len(v) is different from an encoded ULID's length. Invalid encodings produce undefined ULIDs.