id

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package id provides an interface for generating ids.

Index

Constants

This section is empty.

Variables

View Source
var CHARS = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

The characters used in ids. This should not be modified.

View Source
var (
	ErrGenerateUnique = errors.New("unable to generate a UID")
)

Functions

This section is empty.

Types

type Generator

type Generator interface {
	// ID generates an alphanumeric id.
	ID() string

	// UID generates an alphanumeric unique id (UID). The id is guaranteed to be
	// unique to the Generator. It returns ErrGenerateUnique if it can't generate
	// an id that is unique.
	UID() (string, error)
}

A Generator generates ids. It is safe for use in concurrent threads.

func NewGenerator

func NewGenerator(idLen, tries int) Generator

NewGenerator creates a Generator. The first argument it takes is the length of ids (number of characters) that the Generator creates. The second argument is the number of times the Generator tries to create an id before returning an error.

type GeneratorFactory

type GeneratorFactory interface {
	// Make makes a Generator.
	Make() Generator
}

A GeneratorFactory makes Generators.

func NewGeneratorFactory

func NewGeneratorFactory(idLen, tries int) GeneratorFactory

NewGeneratorFactory creates a GeneratorFactory. The first argument it takes is the length of ids (number of characters) that are created by a Generator. The second argument is the number of times a Generator tries to create an id before returning an error.

Jump to

Keyboard shortcuts

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