Documentation
¶
Overview ¶
Package uuid provides a wrapper for handling UUID codes.
Index ¶
- Variables
- func NodeID() string
- func SetRandomNodeID()
- func Within(ttl time.Duration) validation.Rule
- type UUID
- func MakeV1() UUID
- func MakeV3(space UUID, data []byte) UUID
- func MakeV4() UUID
- func MakeV5(space UUID, data []byte) UUID
- func MustParse(s string) UUID
- func NewV1() *UUID
- func NewV3(space UUID, data []byte) *UUID
- func NewV4() *UUID
- func NewV5(space UUID, data []byte) *UUID
- func Normalize(u *UUID) *UUID
- func Parse(s string) (UUID, error)
- func ShouldParse(s string) UUID
Constants ¶
This section is empty.
Variables ¶
var ( // IsV1 confirms the UUID is version 1 IsV1 = versionRule{/* contains filtered or unexported fields */} // IsV3 confirms the UUID is version 3 IsV3 = versionRule{/* contains filtered or unexported fields */} // IsV4 confirms the UUID is version 4 IsV4 = versionRule{/* contains filtered or unexported fields */} // IsV5 confirms the UUID is version 5 IsV5 = versionRule{/* contains filtered or unexported fields */} // IsNotZero confirms the UUID is not zero IsNotZero = versionRule{/* contains filtered or unexported fields */} )
Functions ¶
func SetRandomNodeID ¶
func SetRandomNodeID()
SetRandomNodeID is used to generate a random host ID to be used in V1 UUIDs instead of the MAC address. This is stored in the uuid library as a global constant, so should be called just once when starting the application if you're indending to generate V1 UUIDs to get a node ID that won't change.
func Within ¶
func Within(ttl time.Duration) validation.Rule
Within is a validation method that can be used to determine if the UUID corresponds do UUIDv1 standard and was timestamped within the acceptable time to live from now. If time checks are enabled, future UUIDs will not be allowed, this could be a problem.
Types ¶
type UUID ¶
UUID defines our wrapper for dealing with UUIDs
func MakeV3 ¶ added in v0.69.0
MakeV3 generates a new UUIDv3 using the provided namespace and data. The behaviour is deterministic, that is, the same inputs will always generate the same UUID. This is handy to transform any other types of IDs into UUIDs, among other uses.
In UUIDv3, the data is hashed using MD5 which is a performant algorithm, but it's subject to collision attacks and other vulnerabilities. If security is a concern, use UUIDv5 instead.
func MakeV5 ¶ added in v0.69.0
MakeV5 generates a new UUIDv5 using the provided namespace and data. The behaviour is deterministic, that is, the same inputs will always generate the same UUID. This is handy to transform any other types of IDs into UUIDs, among other uses.
In UUIDv5, the data is hashed using SHA1, a secure algorithm but slower than MD5. If you don't need the security of SHA1 and perfomance is a concern, use UUIDv3 instead.
func NewV3 ¶ added in v0.69.0
NewV3 creates a new MD5 UUID using the provided namespace and data. See MakeV3 for more details.
func NewV5 ¶ added in v0.69.0
NewV5 creates a new SHA1 UUID using the provided namespace and data. See MakeV5 for more details.
func Normalize ¶ added in v0.67.10
Normalize looks at the provided UUID and tries to return a consistent value, which may be nil. Only works with pointers to UUID.
func ShouldParse ¶ added in v0.51.0
ShouldParse will return a UUID if the string is valid, otherwise it will provide a zero UUID.
func (UUID) JSONSchema ¶ added in v0.17.0
func (UUID) JSONSchema() *jsonschema.Schema
JSONSchema returns the jsonschema schema object for the UUID.