Documentation
¶
Overview ¶
Package uuid provides Forge's default UUIDv7 identifier.
Index ¶
- Variables
- type Generator
- type UUID
- func (id UUID) Compare(other UUID) int
- func (id UUID) MarshalJSON() ([]byte, error)
- func (id UUID) MarshalText() ([]byte, error)
- func (id *UUID) Scan(value any) error
- func (id UUID) String() string
- func (id UUID) Time() time.Time
- func (id *UUID) UnmarshalJSON(data []byte) error
- func (id *UUID) UnmarshalText(text []byte) error
- func (id UUID) Value() (driver.Value, error)
- func (id UUID) Variant() byte
- func (id UUID) Version() byte
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("invalid UUIDv7")
ErrInvalid is returned for text or bytes that are not a UUIDv7.
var ErrSequenceExhausted = errors.New("UUIDv7 sequence exhausted for millisecond")
ErrSequenceExhausted is returned when more UUIDs are requested within one millisecond than the monotonic sequence can number.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator creates UUIDv7 values that increase monotonically, also within one millisecond. It is safe for concurrent use.
func NewGenerator ¶
NewGenerator returns a Generator that reads the time from clock and random bytes from random; both are required.
type UUID ¶
type UUID [16]byte
UUID is a 128-bit RFC 9562 UUIDv7 value.
func MustNew ¶
func MustNew() UUID
MustNew is New, and panics when the system entropy source fails. Use it in tests and fixtures.
func New ¶
New returns a new UUIDv7 from the default generator, which uses the system clock and crypto/rand.
func Parse ¶
Parse parses the canonical 36-character text of a UUIDv7; any other UUID version or variant is ErrInvalid.
func (UUID) Compare ¶
Compare compares the UUIDs bytewise: because the timestamp comes first, it orders UUIDs by creation time. It returns -1, 0 or 1.
func (UUID) MarshalJSON ¶
MarshalJSON implements json.Marshaler with the canonical text as a JSON string.
func (UUID) MarshalText ¶
MarshalText implements encoding.TextMarshaler with the canonical text.
func (*UUID) Scan ¶
Scan implements sql.Scanner. It accepts the canonical text, or 16 raw bytes, of a UUIDv7 and rejects any other value.
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler; it accepts only a JSON string holding a UUIDv7.
func (*UUID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler; it accepts only a UUIDv7.