id

package
v0.0.0-...-8f66fda Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Digits     = "0123456789"
	HexDigits  = Digits + "ABCDEF"
	AlphaLower = "abcdefghijklmnopqrstuvwxyz"
	AlphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Variables

View Source
var UuidV4 = NewUuidV4IdGenerator(time.Now().UnixNano(), true)

Functions

This section is empty.

Types

type Generator

type Generator interface {
	Generate() string
}

func NewBase10IdGenerator

func NewBase10IdGenerator(idLength int, lengthUnit LengthUnit) Generator

func NewBase16IdGenerator

func NewBase16IdGenerator(idLength int, lengthUnit LengthUnit) Generator

func NewBase36IdGenerator

func NewBase36IdGenerator(idLength int, lengthUnit LengthUnit) Generator

func NewBase62IdGenerator

func NewBase62IdGenerator(idLength int, lengthUnit LengthUnit) Generator

func NewBaseNIdGenerator

func NewBaseNIdGenerator(idLength int, lengthUnit LengthUnit, encodingCharacters []byte, seed int64) Generator

NewBaseNIdGenerator returns an implementation of Generator that generates id values according to the provided input. idLength and lengthUnit together specify the number of bits or chars that the generated id will contain, and encodingCharacters provides the character set used to represent the generated identifier. Note the base of the identifier is determined by the number of available encoding characters - if one provides 16 characters, then the returned value will be in base-16. The seed is the value given to the underlying random number generator. For convenience, the following helpers are available:

NewBase36IdGenerator - generates ids with digits and lower-case ascii letters
NewBase62IdGenerator - generates ids with digits and both lower- and upper-case ascii letters
NewBase16IdGenerator - generates ids with the hexadecimal values (0-9A-F)
NewBase10IdGenerator - generates ids with just digits

BaseNIdGenerators are all safe for concurrent use by multiple goroutines.

func NewUuidV4IdGenerator

func NewUuidV4IdGenerator(seed int64, withHyphens bool) Generator

NewUuidV4IdGenerator returns a generator that generate versions 4 (i.e. randomly generated) UUIDs. The 'seed' parameter specifies what value to use to start the production of random values, and 'withHyphens' determines if the generated values have the common hyphen separators between the different UUID fields. For convenience, a pre-seeded UuidV4 generator (with hyphens) has been predefined.

UuidV4IdGenerators are safe for concurrent use by multiple goroutines.

type LengthUnit

type LengthUnit = uint8
const (
	Bits LengthUnit = iota
	Chars
)

type Uint

type Uint uint

func (Uint) Format

func (u Uint) Format(f fmt.State, c rune)

func (Uint) String

func (u Uint) String() string

Jump to

Keyboard shortcuts

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