Documentation
¶
Index ¶
- func SetMACAddress(macAddr net.HardwareAddr) error
- func UseHardwareMAC() error
- type UUID
- func NamespaceDNS() UUID
- func NamespaceOID() UUID
- func NamespaceURL() UUID
- func NamespaceX500() UUID
- func NewV1() (uuid UUID)
- func NewV3(ns UUID, name string) (uuid UUID)
- func NewV4() (uuid UUID)
- func NewV5(ns UUID, name string) (uuid UUID)
- func NewV6() (uuid UUID)
- func NewV7() (uuid UUID)
- func NewV8(data []byte) (uuid UUID)
- func Parse(str string) (UUID, error)
- func ParseBytes(bytes []byte) (uuid UUID, err error)
- func (uuid UUID) IsMax() bool
- func (uuid UUID) IsNil() bool
- func (uuid UUID) MarshalBinary() ([]byte, error)
- func (uuid UUID) MarshalText() ([]byte, error)
- func (uuid *UUID) Scan(val any) error
- func (uuid UUID) String() string
- func (uuid UUID) Timestamp() time.Time
- func (uuid *UUID) UnmarshalBinary(in []byte) error
- func (uuid *UUID) UnmarshalText(in []byte) error
- func (uuid UUID) Value() (driver.Value, error)
- func (uuid UUID) Version() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetMACAddress ¶ added in v1.0.0
func SetMACAddress(macAddr net.HardwareAddr) error
SetMACAddress sets the MAC address to be used for generating UUIDs. The MAC address must be 6 bytes long. If the MAC address is not set, a random MAC address will be generated. WARNING: This function is not thread-safe. Make sure to set the MAC address before generating any UUIDs.
func UseHardwareMAC ¶ added in v0.2.0
func UseHardwareMAC() error
UseHardwareMAC sets the MAC address to be used for generating UUIDs to the first valid hardware MAC address found on the system. If no valid hardware MAC address is found, an error is returned. WARNING: This function is not thread-safe. Make sure to set the MAC address before generating any UUIDs.
Types ¶
type UUID ¶
type UUID [16]byte
UUID represents a Universal Unique Identifier as an array containing 16 bytes
func NamespaceDNS ¶ added in v0.2.0
func NamespaceDNS() UUID
func NamespaceOID ¶ added in v0.2.0
func NamespaceOID() UUID
func NamespaceURL ¶ added in v0.2.0
func NamespaceURL() UUID
func NamespaceX500 ¶ added in v0.2.0
func NamespaceX500() UUID
func NewV1 ¶
func NewV1() (uuid UUID)
NewV1 returns a new UUID based on the current timestamp and MAC address. The timestamp is retrieved from the system clock. The MAC address is randomly generated at application startup and can be overridden using SetMACAddress or UseHardwareMAC.
func NewV4 ¶
func NewV4() (uuid UUID)
NewV4 returns a new UUID generated from cryptographically secure random data.
func NewV6 ¶
func NewV6() (uuid UUID)
NewV6 returns a new UUID based on the current timestamp and MAC address. The timestamp is retrieved from the system clock. The MAC address is randomly generated at application startup and can be overridden using SetMACAddress or UseHardwareMAC. Unlike UUIDv1, UUIDv6 is designed to be sortable by time using binary or lexicographical comparison.
func NewV7 ¶
func NewV7() (uuid UUID)
NewV7 returns a new UUID based on the current timestamp and random data. The timestamp is retrieved from the system clock. The random data is generated using the cryptographically secure random number generator. This implementation uses the fractional millisecond approach for ordering of UUIDs within the same millisecond.
func NewV8 ¶
NewV8 returns a new UUID based on the provided data. The data must be 16 bytes long. Bits 48-51 of the UUID are set to 0b1000 (version 8). Bits 64-65 are set to 0b10 (variant RFC 4122/RFC 9562).
func ParseBytes ¶
ParseBytes parses a byte slice and returns the contained UUID or an error The byte slice can be either in binary format (16 bytes) or in string format (36 bytes)
func (UUID) IsNil ¶
IsNil returns true if the UUID contains only zeros and is therefore empty and invalid
func (UUID) MarshalBinary ¶
MarshalBinary provides encoding.BinaryMarshaler
func (UUID) MarshalText ¶
MarshalText provides encoding.TextMarshaler
func (UUID) Timestamp ¶
Timestamp returns the timestamp of the UUID or nil if the UUID does not contain a timestamp
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary provides encoding.BinaryUnmarshaler
func (*UUID) UnmarshalText ¶
UnmarshalText provides encoding.TextUnmarshaler