id

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

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

Go to latest
Published: Jan 28, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

README

* go unique id module

- short(ish)
- url safe
- nonsortable
- random looking
- no obvious pattern
- default (lowercase) config does not include easily confused {l,o,0,1}
- will automagically increase in length if needed to support higher rates

* Example
#+begin_src go
import "github.com/jaw0/unique-id"

uid := id.Unique()

// or

gen := id.NewGenerator()
uid := gen.Unique()

// or

gen := id.NewGenerator( id.WithLength(30), id.WithUpperCase() )
uid := gen.Unique()

#+end_src

* Sample IDs

** default params
- a367ey88sxdfwyb45x4p
- zgy3yrpwi5t5cxwwvjhj

** WithUpperCase()
- hh30PYUpTBeSdnSC
- 5E4igm-0JWKraVL_

** WithLength(30)
- 6pixwwahj44egnwdmlr7cswhfrakvx
- urbnmac6ucguavgh3agffopkhvwgdt

Documentation

Overview

id - AC style unique ids

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAddr

func CheckAddr() uint32

CheckAddr returns the default 32bit host id (IP address), for examination

func Unique

func Unique(opts ...optFunc) string

Unique() returns a unique id ids are url safe, non-sortable, and appear "random-looking" with no visible pattern eg: rk5zzm2zkmt5djecxwj4 if passed the option WithUpperCase(), the id will be shorter and contain upper + lower case letters eg: KaGFYkoJhPs3eNx9 if passed WithLength(n), the id will be no shorter than the requested length

func WithHost

func WithHost(host uint32) func(*Gen)

WithHost specifies a value unique to this server by default the host's IP address is used

func WithHost16

func WithHost16(host uint16) func(*Gen)

WithHost16 specifies a value unique to this server by using a 16bit value, additional bits are available for the time field and more ids can be generated without the length growing

func WithHost16Default

func WithHost16Default() func(*Gen)

WithHost16Default uses the lower 16bits of host's IP see also: WithHost16()

func WithLength

func WithLength(n int) func(*Gen)

WithLength causes the unique id to be at least the requested length by adding randomly generated data if needed

func WithPid

func WithPid(pid uint16) func(*Gen)

WithPid specifies a value unique to this process by default the lower 16bits of the process-id are used

func WithUpperCase

func WithUpperCase() func(*Gen)

WithUpperCase causes the unique id to use uppercase and some (url safe) punctuation in addition to the default of lowercase + numbers

Types

type Gen

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

Gen is a uniqueid generator

func NewGenerator

func NewGenerator(opts ...optFunc) *Gen

NewGenerator returns a new uniqueid generator

func (*Gen) Unique

func (cf *Gen) Unique() string

Unique() returns a unique id

Jump to

Keyboard shortcuts

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