Documentation ¶
Index ¶
- Constants
- Variables
- func Encoding() base32.Encoding
- func MaxTime() time.Time
- func SetSource(src io.Reader) (err error)
- type MonotonicReader
- type TS
- type ULID
- func (u ULID) AppendFormat(dst []byte) []byte
- func (u ULID) Bytes() []byte
- func (u ULID) Compare(o ULID) int
- func (u ULID) MarshalBinary() ([]byte, error)
- func (u ULID) MarshalText() ([]byte, error)
- func (u *ULID) Scan(src interface{}) error
- func (u ULID) String() string
- func (u ULID) Timestamp() TS
- func (u *ULID) UnmarshalBinary(b []byte) error
- func (u *ULID) UnmarshalText(b []byte) error
- func (u ULID) Value() (driver.Value, error)
Constants ¶
const ( // CrockfordBase32 is the ULID encoding alphabet, missing I,L,O,U // to avoid confusion and abuse. See: http://www.crockford.com/wrmg/base32.html CrockfordBase32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" // EncodedLen is the length of a text encoded ULID. EncodedLen = (BinaryLen*8 + 4) / 5 // BinaryLen is the length of a binary ULID. BinaryLen = len(ULID{}) )
Variables ¶
var ( // ErrTimeOverflow is returned if a timestamp >= max time is provided to MonotonicReader. ErrTimeOverflow = errors.New("ulid: timestamp overflows max time") // ErrNegativeTime is returned if a timestamp predating the previous is provided to MonotonicReader. ErrNegativeTime = errors.New("ulid: timestamp predates previous") // ErrMonotonicOverflow is returned when incrementing previous ULID's entropy bytes would result // in an entropy overflow. The solution is to call .Next() again with a later timestamp. ErrMonotonicOverflow = errors.New("ulid: monotonic entropy overflow") )
var ( // ErrInvalidLength is returned when a parse/unmarshal is attempted on data of incorrect length. ErrInvalidLength = errors.New("ulid: invalid data length") // ErrInvalidULID is returned when an invalid text encoding of of a ULID is attempted to be parsed // or unmarshaled. Either due to illegal crockford base32 input data, or due to final character being // outside the possible decodable range of a binary ULID*. // // * due to the 130bit base32 -> 128bit binary decoding losing the // final 2 bits of data, only the following are possible final chars: // // 0 4 8 12 16 20 24 28 // 0123456789ABCDEFGHJKMNPQRSTVWXYZ // 0, 4, 8, C, G, M, R, W // // 0: 00000 // 4: 00100 // 8: 01000 // 12: 01100 // 16: 10000 // 20: 10100 // 24: 11000 // 28: 11100 // // All credit to https://codeberg.org/fansipans for catching and suggesting this fix <3. ErrInvalidULID = errors.New("ulid: invalid ulid data") // ErrBadScanSource is returned when an SQL scan is attempted with a non string/[]byte source. ErrBadScanSource = errors.New("ulid: scan src must be string or []byte") )
Functions ¶
func Encoding ¶
Encoding returns the ULID base32 encoding prepared using CrockfordBase32 and no padding.
Types ¶
type MonotonicReader ¶
type MonotonicReader struct {
// contains filtered or unexported fields
}
MonotonicReader wraps a reader to provide montonically increasing ULID values.
func NewMonotonicReader ¶
func NewMonotonicReader(src io.Reader) (*MonotonicReader, error)
NewMonotonicReader returns a new instance for given entropy source and read buffer size. Note that 'src' MUST yield random bytes or else monotonic reads are not guaranteed to terminate, since there may not be enough entropy to compute a monotonic increment.
type TS ¶
type TS uint64
TS represents a Unix time in milliseconds.
type ULID ¶
type ULID [16]byte
ULID: Universally Unique Lexicographically Sortable Identifier.
func ParseString ¶
ParseString will parse a text-encoded ULID from string.
func (ULID) AppendFormat ¶
AppendFormat append text encoded ULID to 'dst'.
func (ULID) Compare ¶
Compare returns integer value from comparison between receiving and argument ULID lexographically.
0 -> (u == o), -1 -> (u < o), 1 -> (u > 0).
func (ULID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (ULID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ULID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*ULID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.