Documentation
¶
Overview ¶
Package objectid provides a way to generate MongoDB-style ObjectID. ref: https://www.mongodb.com/docs/manual/reference/method/ObjectId
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetCounter ¶
func SetCounter(c Counter)
SetCounter sets the global counter value for generating ObjectIDs.
func SetMachineAndProcessID ¶
func SetMachineAndProcessID(pid MachineProcessID)
SetMachineAndProcessID sets the machine and process ID for generating ObjectIDs.
Types ¶
type Counter ¶
type Counter uint32
Counter is the implementation of the counter in ObjectID.
func NewSecureCounter ¶
NewSecureCounter generates a new secure counter value for generating ID.
type ID ¶
type ID [timestampSize + processSize + counterSize]byte
ID is the implementation of MongoDB ObjectID.
var Nil ID
Nil is a zero value of the ID.
func New ¶
func New() ID
New generates a new ID using the current time epochs, machine and process ids, and the global counter value.
func (ID) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (ID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. This is useful when using the ID as a map key during JSON marshalling.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. This is useful when using the ID as a map key during JSON unmarshalling.
type MachineProcessID ¶
type MachineProcessID [processSize]byte
MachineProcessID is the implementation of the machine and process id portion for the ObjectID.
func NewMachineProcessID ¶
func NewMachineProcessID(reader io.Reader) (MachineProcessID, error)
NewMachineProcessID generates a new machine and process ids for generating ID.