guid

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2017 License: MIT Imports: 6 Imported by: 1

README

GUID

Build Status GoDoc Go Report Card License

Simple, thread-safe MongoDB style GUID generator.

Examples
func main {
	// Create a new 12-byte globally-unique identifier
	id := guid.New96()
	fmt.Println(hex.EncodeToString(id.Bytes()))
}
func main {
	// Create a new 16-byte globally-unique identifier
	id := guid.New128()
	fmt.Println(hex.EncodeToString(id.Bytes()))
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GUID

type GUID interface {
	CreatedAt() time.Time
	WriteTo(w io.Writer) (int64, error)
	Bytes() []byte
}

GUID is an interface unifying identifiers of different lengths

type GUID128

type GUID128 [16]byte

GUID128 is a 16-byte globally unique identifier

func New128

func New128() GUID128

New128 creates a 128bit/16byte global identifier

Example
package main

import (
	"encoding/hex"
	"fmt"

	guid "github.com/bsm/go-guid"
)

func main() {
	// Create a new 16-byte globally-unique identifier
	id := guid.New128()
	fmt.Println(hex.EncodeToString(id.Bytes()))
}
Output:

func (GUID128) Bytes

func (g GUID128) Bytes() []byte

Bytes returns a byte slice

func (GUID128) CreatedAt

func (g GUID128) CreatedAt() time.Time

CreatedAt extract the timestamp at which the GUID was created

func (GUID128) WriteTo

func (g GUID128) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo

type GUID96

type GUID96 [12]byte

GUID96 is a 12-byte globally unique identifier

func New96

func New96() GUID96

New96 creates a 96bit/12byte global identifier

Example
package main

import (
	"encoding/hex"
	"fmt"

	guid "github.com/bsm/go-guid"
)

func main() {
	// Create a new 12-byte globally-unique identifier
	id := guid.New96()
	fmt.Println(hex.EncodeToString(id.Bytes()))
}
Output:

func (GUID96) Bytes

func (g GUID96) Bytes() []byte

Bytes returns a byte slice

func (GUID96) CreatedAt

func (g GUID96) CreatedAt() time.Time

CreatedAt extract the timestamp at which the GUID was created

func (GUID96) WriteTo

func (g GUID96) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo

Jump to

Keyboard shortcuts

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