Documentation
¶
Index ¶
- Variables
- func Validate(s string) error
- type OUID
- func (cu OUID) Hex() string
- func (cu OUID) IsZero() bool
- func (cu OUID) MarshalJSON() ([]byte, error)
- func (cu OUID) MarshalText() ([]byte, error)
- func (c *OUID) Scan(value any) error
- func (c OUID) String() string
- func (cu OUID) ToObjectID() objectID
- func (cu OUID) UUID() uuid.UUID
- func (cu *OUID) UnmarshalJSON(b []byte) error
- func (cu *OUID) UnmarshalText(b []byte) error
- func (c OUID) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidHex = errors.New("the provided hex string is not a valid ObjectID")
ErrInvalidHex indicates that a hex string cannot be converted to an ObjectID.
View Source
var NilObjectID objectID
NilObjectID is the zero value for ObjectID.
Functions ¶
Types ¶
type OUID ¶
OUID will transform MongoDB's ObjectID (12 bytes) into UUID format (16 bytes). The last 4 bytes are always zero.
var (
Nil OUID
)
func FromObjectID ¶
func FromObjectID(oid objectID) OUID
FromObjectID converts MongoDB's ObjectID to OUID
func FromObjectIDHex ¶
func FromUUIDString ¶
FromUUIDString creates OUID from a UUID string
The UUID string must be a valid OUID (the last 4 bytes are zero).
func (OUID) MarshalJSON ¶
MarshalJSON outputs OUID as a JSON string (ObjectID hex).
func (OUID) MarshalText ¶
MarshalText returns the OUID as text (hex of ObjectID part).
func (OUID) ToObjectID ¶
func (cu OUID) ToObjectID() objectID
ToObjectID converts OUID back to MongoDB's ObjectID
func (*OUID) UnmarshalJSON ¶
UnmarshalJSON parses JSON into OUID. Supports:
- null → leave unchanged
- "507f1f77bcf86cd799439011" (24 hex chars)
- {"$oid": "..."} (Mongo Extended JSON)
- "" → Nil
func (*OUID) UnmarshalText ¶
UnmarshalText parses OUID from hex text.
Click to show internal directories.
Click to hide internal directories.