uuid.go
uuid.go - Overview
-
Overview This file defines a
UUID
type that encapsulates theuuid.UUID
from thegithub.com/google/uuid
package, providing methods for creating, manipulating, and serializing UUIDs. It also implements theValuer
interface for database interaction and JSON serialization/deserialization. -
Detailed Documentation
UUID
- Purpose: Represents a UUID value.
- Members:
val uuid.UUID
: The underlying UUID value.
NewUUID
- Purpose: Creates a new
UUID
from a string representation. - Parameters:
value string
: The string representation of the UUID.
- Returns:
UUID
: The newUUID
instance.error
: An error if the string is not a valid UUID.
NewUUIDFromBytes
- Purpose: Creates a new
UUID
from a byte slice. - Parameters:
value []byte
: The byte slice representing the UUID.
- Returns:
UUID
: The newUUID
instance.error
: An error if the byte slice is not a valid UUID.
MustNewUUID
- Purpose: Creates a new
UUID
from a string representation, panicking on error. - Parameters:
val string
: The string representation of the UUID.
- Returns:
UUID
: The newUUID
instance.
- Panics: If the input string is not a valid UUID.
GenerateUUID
- Purpose: Generates a new UUID using UUID version 7.
- Returns:
UUID
: The newly generatedUUID
instance.
- Panics: If there is an error generating the UUID.
IsZero
- Purpose: Checks if the UUID is the zero UUID.
- Parameters:
enum UUID
: TheUUID
instance.
- Returns:
bool
:true
if the UUID is zero,false
otherwise.
StringValue
- Purpose: Returns the string representation of the UUID.
- Parameters:
enum UUID
: TheUUID
instance.
- Returns:
string
: The string representation of the UUID.
MarshalJSON
- Purpose: Marshals the UUID to JSON.
- Parameters:
enum UUID
: TheUUID
instance.
- Returns:
[]byte
: The JSON representation of the UUID.error
: An error if marshaling fails.
UnmarshalJSON
- Purpose: Unmarshals the UUID from JSON.
- Parameters:
enum *UUID
: A pointer to theUUID
instance.data []byte
: The JSON data to unmarshal.
- Returns:
error
: An error if unmarshaling fails.
Value
- Purpose: Returns the UUID as a driver.Value for database interaction.
- Parameters:
enum UUID
: TheUUID
instance.
- Returns:
driver.Value
: The UUID as adriver.Value
.error
: An error if any.
Scan
- Purpose: Scans a value into the UUID.
- Parameters:
enum *UUID
: A pointer to theUUID
instance.val interface{}
: The value to scan from.
- Returns:
error
: An error if the value cannot be scanned into a UUID.
- Code Examples
Not applicable.
- Clarity and Accuracy
The documentation accurately reflects the code.
- Markdown & MDX Perfection
The markdown syntax is correct.
- Edge Cases To Avoid Breaking MDX:
No issues found.
- Getting Started Relevance
Include in Getting Started: NO