oid

package
v0.0.0-...-d078b10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 11

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

View Source
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

func FromString(id string) ObjectID

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 NewUUIDv5

func NewUUIDv5(id string) ObjectID

NewUUIDv5 returns a new version 5 uuid in the objectID namespace

func (ObjectID) MarshalBSONValue

func (oid ObjectID) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue provides the bson.ValueMarshaler interface.

func (ObjectID) MarshalJSON

func (oid ObjectID) MarshalJSON() ([]byte, error)

MarshalJSON ensures the ObjectID marhsals correctly.

func (ObjectID) String

func (oid ObjectID) String() string

func (ObjectID) Type

func (oid ObjectID) Type() Type

func (*ObjectID) UnmarshalBSONValue

func (oid *ObjectID) UnmarshalBSONValue(t bsontype.Type, b []byte) error

UnmarshalBSONValue provides the bson.ValueUnmarshaler interace.

func (*ObjectID) UnmarshalJSON

func (oid *ObjectID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal string-type json to the appropriate ObjectID type.

type Type

type Type int
const (
	TypeNil Type = iota
	TypeUUID
	TypeBSONID
	TypeString
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL