Documentation ¶
Index ¶
- Constants
- Variables
- type Generator
- func NewBase10IdGenerator(idLength int, lengthUnit LengthUnit) Generator
- func NewBase16IdGenerator(idLength int, lengthUnit LengthUnit) Generator
- func NewBase36IdGenerator(idLength int, lengthUnit LengthUnit) Generator
- func NewBase62IdGenerator(idLength int, lengthUnit LengthUnit) Generator
- func NewBaseNIdGenerator(idLength int, lengthUnit LengthUnit, encodingCharacters []byte, seed int64) Generator
- func NewUuidV4IdGenerator(seed int64, withHyphens bool) Generator
- type LengthUnit
- type Uint
Constants ¶
const ( Digits = "0123456789" HexDigits = Digits + "ABCDEF" AlphaLower = "abcdefghijklmnopqrstuvwxyz" AlphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
Variables ¶
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 ¶
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.