Documentation
¶
Overview ¶
Package objectid package implements MongoDB's ObjectID type.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidBase64 = errors.New("invalid base64")
ErrInvalidBase64 is returned when an invalid base64 string is provided.
var ErrInvalidHex = errors.New("invalid hex")
ErrInvalidHex is returned when an invalid hex string is provided.
var ErrInvalidTimeFormat = errors.New("invalid time format")
ErrInvalidTimeFormat is returned when an invalid time format is provided.
Functions ¶
func GenerateTo ¶
func GenerateTo(objectID *ObjectID)
GenerateTo generates a new ObjectID and writes it to the provided ObjectID pointer.
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
FromBase64 decodes a base64 string into an ObjectID.
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 FromTime ¶ added in v1.1.0
FromTime creates a new ObjectID from a time string. The time string must be in one of the formats: RFC3339, "2006-01-02T15:04-07:00", "2006-01-02T15:04", "2006-01-02T15-07:00", "2006-01-02",
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.