Documentation
¶
Index ¶
- Variables
- func MarshalJSON(val any) ([]byte, error)
- func UnmarshalJSON(data []byte, val any) error
- func Validate(s string) error
- type ObjectID
- func (id ObjectID) Hex() string
- func (id ObjectID) IsZero() bool
- func (id ObjectID) MarshalJSON() ([]byte, error)
- func (id ObjectID) MarshalText() ([]byte, error)
- func (id ObjectID) String() string
- func (id ObjectID) Timestamp() time.Time
- func (id *ObjectID) UnmarshalJSON(b []byte) error
- func (id *ObjectID) UnmarshalText(b []byte) error
- type ObjectUUID
- func (cu ObjectUUID) Hex() string
- func (cu ObjectUUID) IsZero() bool
- func (cu ObjectUUID) MarshalJSON() ([]byte, error)
- func (cu ObjectUUID) MarshalText() ([]byte, error)
- func (c *ObjectUUID) Scan(value any) error
- func (c ObjectUUID) String() string
- func (cu ObjectUUID) ToObjectID() ObjectID
- func (cu *ObjectUUID) UnmarshalJSON(b []byte) error
- func (cu *ObjectUUID) UnmarshalText(b []byte) error
- func (c ObjectUUID) Value() (driver.Value, error)
- type ObjectUUIDs
- func (m *ObjectUUIDs) Add(ids ...ObjectUUID)
- func (m *ObjectUUIDs) Contains(id ObjectUUID) bool
- func (m *ObjectUUIDs) IsEmpty() bool
- func (m *ObjectUUIDs) Len() int
- func (m *ObjectUUIDs) Remove(ids ...ObjectUUID)
- func (m *ObjectUUIDs) UnsafeAdd(ids ...ObjectUUID)
- func (m *ObjectUUIDs) UnsafeRemove(ids ...ObjectUUID)
- func (m *ObjectUUIDs) UnsafeValue() []ObjectUUID
Constants ¶
This section is empty.
Variables ¶
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.
Functions ¶
func MarshalJSON ¶
func UnmarshalJSON ¶
Types ¶
type ObjectID ¶
type ObjectID [12]byte
ObjectID is the BSON ObjectID type.
var NilObjectID ObjectID
NilObjectID is the zero value for ObjectID.
func ObjectIDFromHex ¶
ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.
func (ObjectID) MarshalJSON ¶
MarshalJSON returns the ObjectID as a string
func (ObjectID) MarshalText ¶
MarshalText returns the ObjectID as UTF-8-encoded text. Implementing this allows us to use ObjectID as a map key when marshalling JSON. See https://pkg.go.dev/encoding#TextMarshaler
func (*ObjectID) UnmarshalJSON ¶
UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 24 bytes long, it will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes long, it will be populated with the BSON representation of the ObjectID. This method also accepts empty strings and decodes them as NilObjectID. For any other inputs, an error will be returned.
func (*ObjectID) UnmarshalText ¶
UnmarshalText populates the byte slice with the ObjectID. Implementing this allows us to use ObjectID as a map key when unmarshalling JSON. See https://pkg.go.dev/encoding#TextUnmarshaler
type ObjectUUID ¶
ObjectUUID will transform MongoDB's ObjectID (12 bytes) into UUID format (16 bytes). The last 4 bytes are always zero.
var (
Nil ObjectUUID
)
func FromObjectID ¶
func FromObjectID(oid ObjectID) ObjectUUID
FromObjectID converts MongoDB's ObjectID to ObjectUUID
func FromObjectIDHex ¶
func FromObjectIDHex(oidHex string) (ObjectUUID, error)
func New ¶
func New() ObjectUUID
func (ObjectUUID) IsZero ¶
func (cu ObjectUUID) IsZero() bool
func (ObjectUUID) MarshalJSON ¶
func (cu ObjectUUID) MarshalJSON() ([]byte, error)
MarshalJSON outputs ObjectUUID as a JSON string (ObjectID hex).
func (ObjectUUID) MarshalText ¶
func (cu ObjectUUID) MarshalText() ([]byte, error)
MarshalText returns the ObjectUUID as text (hex of ObjectID part).
func (*ObjectUUID) Scan ¶
func (c *ObjectUUID) Scan(value any) error
Scan implements sql.Scanner (for reading from DB)
func (ObjectUUID) String ¶
func (c ObjectUUID) String() string
func (ObjectUUID) ToObjectID ¶
func (cu ObjectUUID) ToObjectID() ObjectID
ToObjectID converts ObjectUUID back to MongoDB's ObjectID
func (*ObjectUUID) UnmarshalJSON ¶
func (cu *ObjectUUID) UnmarshalJSON(b []byte) error
UnmarshalJSON parses JSON into ObjectUUID. Supports:
- null → leave unchanged
- "507f1f77bcf86cd799439011" (24 hex chars)
- {"$oid": "..."} (Mongo Extended JSON)
- "" → Nil
func (*ObjectUUID) UnmarshalText ¶
func (cu *ObjectUUID) UnmarshalText(b []byte) error
UnmarshalText parses ObjectUUID from hex text.
type ObjectUUIDs ¶
type ObjectUUIDs struct {
// contains filtered or unexported fields
}
func NewObjectUUIDs ¶
func NewObjectUUIDs(ids ...ObjectUUID) *ObjectUUIDs
func (*ObjectUUIDs) Add ¶
func (m *ObjectUUIDs) Add(ids ...ObjectUUID)
func (*ObjectUUIDs) Contains ¶
func (m *ObjectUUIDs) Contains(id ObjectUUID) bool
func (*ObjectUUIDs) IsEmpty ¶
func (m *ObjectUUIDs) IsEmpty() bool
func (*ObjectUUIDs) Len ¶
func (m *ObjectUUIDs) Len() int
func (*ObjectUUIDs) Remove ¶
func (m *ObjectUUIDs) Remove(ids ...ObjectUUID)
func (*ObjectUUIDs) UnsafeAdd ¶
func (m *ObjectUUIDs) UnsafeAdd(ids ...ObjectUUID)
func (*ObjectUUIDs) UnsafeRemove ¶
func (m *ObjectUUIDs) UnsafeRemove(ids ...ObjectUUID)
func (*ObjectUUIDs) UnsafeValue ¶
func (m *ObjectUUIDs) UnsafeValue() []ObjectUUID