Skip to content

A unique id generator that produces ids like mongodb object id.

Notifications You must be signed in to change notification settings

coolbed/mgo-oid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

mgo-oid

A unique id generator that produces ids like mongodb object id. This generator implementation refers the source code of mgo project, that's why it has mgo as its name prefix.

ObjectId

Object id is a globally unique identifier for object in mongodb. It consists of 12 bytes, divided as follows:

  • a 4-byte value representing the seconds since the Unix epoch
  • a 3-byte machine identifier
  • a 2-byte process id
  • a 3-byte counter, starting with a random value

Installation

Use the go command:

$ go get github.com/coolbed/mgo-oid

Example

package main

import (
	"fmt"

	"github.com/coolbed/mgo-oid"
)

func main() {
	objectID := oid.NewOID()
	fmt.Println("object id:", objectID.String())
	fmt.Println("object timestamp", objectID.Timestamp())
}

About

A unique id generator that produces ids like mongodb object id.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages