Documentation ¶
Overview ¶
Package ulid provides a Universally Unique Lexicographically Sortable Identifier (ULID) implementation in Go.
Index ¶
- Constants
- Variables
- func MaxTime() int64
- func Now() int64
- func ReverseTime(rms int64) int64
- func SetSource(src io.Reader) error
- type MonotonicReader
- type ULID
- func (u ULID) AppendFormat(dst []byte) []byte
- func (u ULID) Bytes() []byte
- func (u ULID) MarshalBinary() ([]byte, error)
- func (u ULID) MarshalBinaryTo(data []byte) error
- func (u ULID) MarshalText() ([]byte, error)
- func (u ULID) String() string
- func (u ULID) Time() int64
- func (u ULID) UnmarshalBinary(b []byte) error
- func (u ULID) UnmarshalText(b []byte) error
Examples ¶
Constants ¶
const ( // Encodingis Crockford's Base32 // https://www.crockford.com/base32.html Encoding = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" // Size is the length of a ULID in bytes. Size = len(ULID{}) // EncodedSize is the length of a ULID in chars. EncodedSize = (Size*8 + 4) / 5 )
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 the length of the ULID is invalid. ErrInvalidLength = errors.New("ulid: invalid length") // ErrInvalidChar is returned when the char is invalid. ErrInvalidChar = errors.New("ulid: invalid character") // ErrInvalidULID is returned when the ULID is invalid. ErrInvalidULID = errors.New("ulid: invalid ULID") // ErrDataSize is returned when the data size is invalid. ErrDataSize = errors.New("ulid: invalid data size") )
Functions ¶
func ReverseTime ¶
ReverseTime returns the reverse time component of the ULID.
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.
func (*MonotonicReader) Next ¶
func (r *MonotonicReader) Next(ts int64, dst *ULID) error
Next calculates next available ULID for given Timestamp.
func (*MonotonicReader) NextReverse ¶
func (r *MonotonicReader) NextReverse(ts int64, dst *ULID) error
NextReverse calculates next available ULID for given Timestamp.
type ULID ¶
type ULID [16]byte
ULID is a 128-bit Universally Unique Lexicographically Sortable Identifier.
Example ¶
package main import ( "fmt" "github.com/zeiss/pkg/ulid" ) func main() { fmt.Println(ulid.MustNew()) }
Output:
func MustNewReverse ¶
func MustNewReverse() ULID
MustNewReverse returns a new ULID with reverse time.
func ParseString ¶
ParseString parses a ULID from a string.
func (ULID) AppendFormat ¶
AppendFormat append text encoded ULID to 'dst'.
func (ULID) MarshalBinary ¶
MarshalBinary encodes a ULID into binary form.
func (ULID) MarshalBinaryTo ¶
MarshalBinaryTo encodes a ULID into binary form.
func (ULID) MarshalText ¶
MarshalText encodes a ULID into text form by implementing encoding.TextMarshaler.
func (ULID) UnmarshalBinary ¶
UnmarshalBinary decodes a ULID from binary form.
func (ULID) UnmarshalText ¶
UnmarshalText decodes a ULID from text form.