Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectId package for Go language

This package provides build a unique object identifier for the high concurrent environment.

The ObjectId can instead of GUID,and are stored as 12-bytes.

Reference from : ObjectId of Mongodb

ObjectId is a 12-byte BSON type, constructed using:

a 4-byte value representing the seconds since the Unix epoch,

a 3-byte machine identifier,

a 2-byte process id, and

a 3-byte counter, starting with a random value.

Installation

Use the go command:

go get github.com/nobugtodebug/go-objectid

Example

package main

import (
	"fmt"
	"github.com/nobugtodebug/go-objectid"
)

func main() {
	objid := objectid.New()
	fmt.Printf("ObjectId: %s\n", objid)
	objid = objectid.Parse("55cc60946f29581a606930aa")
	fmt.Printf("%d-%d-%d-%d\n", objid.Timestamp(), objid.Machine(), objid.Pid(), objid.Increment())
}

About

ObjectId(Unique Identifier) package for Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages