Documentation ¶
Overview ¶
Package id provides an interface for generating ids.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CHARS = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
The characters used in ids. This should not be modified.
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 ¶
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.