Documentation
¶
Overview ¶
Package uuid provides a wrapper for handling UUID codes.
Index ¶
- Variables
- func NodeID() string
- func Normalize(u *UUID)
- func SetRandomNodeID()
- func Within(ttl time.Duration) validation.Rule
- type Identify
- type UUID
- func MakeV1() UUIDdeprecated
- func MakeV3(space UUID, data []byte) UUIDdeprecated
- func MakeV4() UUIDdeprecated
- func MakeV5(space UUID, data []byte) UUIDdeprecated
- func MustParse(s string) UUID
- func NewV1() *UUIDdeprecated
- func NewV3(space UUID, data []byte) *UUIDdeprecated
- func NewV4() *UUIDdeprecated
- func NewV5(space UUID, data []byte) *UUIDdeprecated
- func Parse(s string) (UUID, error)
- func ShouldParse(s string) UUID
- func V1() UUID
- func V3(space UUID, data []byte) UUID
- func V4() UUID
- func V5(space UUID, data []byte) UUID
- type Version
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 Normalize ¶ added in v0.67.10
func Normalize(u *UUID)
Normalize will ensure that zero value UUIDs will be empty strings instead of zeros.
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 intending 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 Identify ¶ added in v0.73.0
type Identify struct {
UUID UUID `json:"uuid,omitempty" jsonschema:"title=UUID,description=Universally Unique Identifier."`
}
Identify defines a struct that can be used to identify a document by a UUID.
func IdentifyParse ¶ added in v0.73.0
IdentifyParse will parse the provided string as a UUID in the UUID field, or panic. This is mainly meant to be used in tests.
func IdentifyV1 ¶ added in v0.73.0
func IdentifyV1() Identify
IdentifyV1 is a helper method to generate a V1 uuid ready to embed.
func IdentifyV3 ¶ added in v0.73.0
IdentifyV3 is a helper method to generate a V3 uuid ready to embed.
func IdentifyV4 ¶ added in v0.73.0
func IdentifyV4() Identify
IdentifyV4 is a helper method to generate a V4 uuid ready to embed.
func IdentifyV5 ¶ added in v0.73.0
IdentifyV5 is a helper method to generate a V5 uuid ready to embed.
type UUID ¶
type UUID string
UUID defines a string wrapper for dealing with UUIDs using the google uuid package for parsing and specific method support. This implementation has been optimized for convenience and JSON conversion as opposed to performance.
Note that this package is not registered inside its own schema. We instead rely on the `"format"` parameter already included in JSON Schema.
Constants for empty and zero states.
func MakeV3
deprecated
added in
v0.69.0
MakeV3 generates a new UUIDv3 using the provided namespace and data. The behavior 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 is subject to collision attacks and other vulnerabilities. If security is a concern, use UUIDv5 instead.
Deprecated: use V3() instead.
func MakeV5
deprecated
added in
v0.69.0
MakeV5 generates a new UUIDv5 using the provided namespace and data. The behavior 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 performance is a concern, use UUIDv3 instead.
Deprecated: use V5() instead.
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 V3 ¶ added in v0.73.0
V3 generates a new UUIDv3 using the provided namespace and data. The behavior 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 is subject to collision attacks and other vulnerabilities. If security is a concern, use UUIDv5 instead.
func V5 ¶ added in v0.73.0
V5 generates a new UUIDv5 using the provided namespace and data. The behavior 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 performance is a concern, use UUIDv3 instead.
func (UUID) JSONSchemaExtend ¶ added in v0.73.0
func (UUID) JSONSchemaExtend(s *jsonschema.Schema)
JSONSchemaExtend ensures the schema contains the additional UUID format wherever it is used.
func (UUID) Timestamp ¶
Timestamp extracts the time. Anything other than a v1 UUID will provide zero time without an error, so ensure your error checks are performed previously.
func (*UUID) UnmarshalText ¶ added in v0.73.0
UnmarshalText will ensure the UUID is always a valid UUID when unmarshalling.