Documentation
¶
Overview ¶
Package ulid provides ULID generation helpers (Universally Unique Lexicographically Sortable Identifiers).
ULIDs encode time for lexical ordering, but this package does not make ULIDs monotonic within the same millisecond. Generators are concurrency-safe iff the injected RNG is safe.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidULID = errors.New("randutil: invalid ulid")
ErrInvalidULID is returned when parsing fails.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds ULIDs using a core RNG.
Concurrency: safe for concurrent use if the underlying RNG is safe.
func New ¶
func New(rng rng) *Generator
New returns a ULID Generator. If rng is nil, crypto/rand is used.
func NewWithClock ¶
NewWithClock returns a ULID Generator bound to rng and clock. If rng is nil, crypto/rand is used. If now is nil, time.Now is used.
func NewWithSource ¶
NewWithSource returns a ULID Generator bound to src.
func (*Generator) ULID ¶
ULID returns a ULID based on the current time and random data.
Example ¶
gen := Default()
id, err := gen.ULID()
if err != nil {
fmt.Println("error")
return
}
parsed, err := Parse(id.String())
if err != nil {
fmt.Println("error")
return
}
fmt.Println(len(id))
fmt.Println(parsed == id)
Output: 26 true