objectid

package module
v0.0.0-...-bf7daf7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2015 License: MIT Imports: 7 Imported by: 12

README

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())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObjectId

type ObjectId struct {
	// contains filtered or unexported fields
}

func New

func New() *ObjectId

func Parse

func Parse(input string) *ObjectId

func (*ObjectId) CreationTime

func (this *ObjectId) CreationTime() time.Time

func (*ObjectId) Equal

func (this *ObjectId) Equal(other *ObjectId) bool

func (*ObjectId) Increment

func (this *ObjectId) Increment() int32

func (*ObjectId) Machine

func (this *ObjectId) Machine() int32

func (*ObjectId) Pid

func (this *ObjectId) Pid() int32

func (*ObjectId) String

func (this *ObjectId) String() string

func (*ObjectId) Timestamp

func (this *ObjectId) Timestamp() int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL