Documentation ¶
Overview ¶
Package objectid package implements MongoDB's ObjectID type.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidBase64 = fmt.Errorf("invalid base64")
View Source
var ErrInvalidHex = fmt.Errorf("invalid hex")
ErrInvalidHex is returned when an invalid hex string is provided.
View Source
var ErrInvalidTimeFormat = fmt.Errorf("invalid time format")
Functions ¶
func GenerateTo ¶
func GenerateTo(objectID *ObjectID)
GenerateTo generates a new ObjectID and writes it to the provided ObjectID
Example ¶
counter.Store(0x6b5f9e) // as a user of this package, you don't need to do this, but it's done here to ensure the same output var oid ObjectID GenerateTo(&oid) fmt.Println(oid.Hex())
Output: 5c2aad805f9e6b5f9e6b5f9f
Types ¶
type ObjectID ¶
type ObjectID [12]byte
ObjectID is a 12-byte unique identifier for a MongoDB document.
func FromBase64 ¶ added in v1.1.0
func FromHex ¶
FromHex creates a new ObjectID from a hex string.
Example ¶
g, err := FromHex("5c2aad805f9e6b5f9e6b5fa3") if err != nil { fmt.Println(err) } else { fmt.Println(g.Hex()) }
Output: 5c2aad805f9e6b5f9e6b5fa3
func New ¶
func New() ObjectID
New generates a new ObjectID.
Example ¶
counter.Store(0x6b5f9e) // as a user of this package, you don't need to do this, but it's done here to ensure the same output g := New() fmt.Println(g.Hex())
Output: 5c2aad805f9e6b5f9e6b5f9f
func (ObjectID) Base64 ¶ added in v1.1.0
Base64 returns the hex encoding of the ObjectID as a string.
Click to show internal directories.
Click to hide internal directories.