id

package
v0.0.0-...-4125756 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package id is a globally unique id generator suited for web scale. Features:

  • Size: 12 bytes (96 bits), smaller than UUID, larger than snowflake
  • Base32 hex encoded by default (16 bytes storage when transported as printable string)
  • K-ordered
  • Embedded time with 1 second precision
  • Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process

example:

// creating a global unique ID.
ID := id.New()
// Output:
	9m4e2mr0ui3e8a215n4g

// Generating prefixed ID in case you want to generate a lot of prefixed id
//	eg: prefixed id for databases
generator := id.NewGenerator("user")
ID := generator.Generate()
//Output:
	user/9m4e2mr0ui3e8a215n4g

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() string

New generates a globally unique ID

Types

type Generator

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

Generator will generate prefixed ID.

func NewGenerator

func NewGenerator(prefix string) *Generator

NewGenerator creates a new ID generator with prefix. the prefix format will follow the partition convention as follows: <PREFIX>/<GLOBALLY_UNIQUE_ID>

func (*Generator) Generate

func (g *Generator) Generate() string

Generate generates a prefixed globally unique ID.

Jump to

Keyboard shortcuts

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