Skip to main content

uuid.go

uuid.go - Overview

  1. Overview This file defines a UUID type that encapsulates the uuid.UUID from the github.com/google/uuid package, providing methods for creating, manipulating, and serializing UUIDs. It also implements the Valuer interface for database interaction and JSON serialization/deserialization.

  2. 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 new UUID 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 new UUID 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 new UUID 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 generated UUID instance.
  • Panics: If there is an error generating the UUID.

IsZero

  • Purpose: Checks if the UUID is the zero UUID.
  • Parameters:
    • enum UUID: The UUID instance.
  • Returns:
    • bool: true if the UUID is zero, false otherwise.

StringValue

  • Purpose: Returns the string representation of the UUID.
  • Parameters:
    • enum UUID: The UUID instance.
  • Returns:
    • string: The string representation of the UUID.

MarshalJSON

  • Purpose: Marshals the UUID to JSON.
  • Parameters:
    • enum UUID: The UUID 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 the UUID 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: The UUID instance.
  • Returns:
    • driver.Value: The UUID as a driver.Value.
    • error: An error if any.

Scan

  • Purpose: Scans a value into the UUID.
  • Parameters:
    • enum *UUID: A pointer to the UUID instance.
    • val interface{}: The value to scan from.
  • Returns:
    • error: An error if the value cannot be scanned into a UUID.
  1. Code Examples

Not applicable.

  1. Clarity and Accuracy

The documentation accurately reflects the code.

  1. Markdown & MDX Perfection

The markdown syntax is correct.

  1. Edge Cases To Avoid Breaking MDX:

No issues found.

  1. Getting Started Relevance

Include in Getting Started: NO