Documentation ¶
Overview ¶
Package oid contains wrappers for creating bson ObjectIDs that marshals correctly according to the bson specification: http://bsonspec.org/spec.html
Index ¶
- Constants
- type ObjectID
- func (oid ObjectID) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (oid ObjectID) MarshalJSON() ([]byte, error)
- func (oid ObjectID) String() string
- func (oid ObjectID) Type() Type
- func (oid *ObjectID) UnmarshalBSONValue(t bsontype.Type, b []byte) error
- func (oid *ObjectID) UnmarshalJSON(b []byte) error
- type Type
Constants ¶
const Size = 16
Size of a UUID in bytes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectID ¶
type ObjectID struct {
// contains filtered or unexported fields
}
ObjectID implements a bson compatible fusion of bson ObjectID, UUID and string types. Depending on the initialization, this type marshals to the correct bson type (and sub-type) for each type.
func FromString ¶
FromString tries to parse a hex-encoded mongo ObjectID/UUID string, and returns an error if the string is not a valid UUID.
func NewBSONID ¶
func NewBSONID() ObjectID
NewBSONID initialize a new bson-type ObjectID (used by default by mongo)
func NewUUIDv4 ¶
func NewUUIDv4() ObjectID
NewUUIDv4 creates a new ObjectID initialized with a UUID v4 (random). In the rare event that the RNG returns an error, the null UUID is returned.
func (ObjectID) MarshalBSONValue ¶
MarshalBSONValue provides the bson.ValueMarshaler interface.
func (ObjectID) MarshalJSON ¶
MarshalJSON ensures the ObjectID marhsals correctly.
func (*ObjectID) UnmarshalBSONValue ¶
UnmarshalBSONValue provides the bson.ValueUnmarshaler interace.
func (*ObjectID) UnmarshalJSON ¶
UnmarshalJSON unmarshal string-type json to the appropriate ObjectID type.