/idgen

A package for generating random identifiers.

Primary LanguageGoMIT LicenseMIT

This package was developed by Silicon Ally while working on a project for Adventure Scientists. Many thanks to Adventure Scientists for supporting our open source mission!

idgen

GoDoc

idgen is a simple, zero-dependency Go library for generating random identifiers. It is useful in places where one might want a UUID-like identifier, but want to customize length or allowed characters.

Usage

import "github.com/Silicon-Ally/idgen"

...
// For security-sensitive applications, use a cryptographically secure rand
// source, like https://github.com/Silicon-Ally/cryptorand for example.
r := rand.New(rand.NewSource(12345))

// Initialize generator with your ID requirements...
generator, err := idgen.New(r, idgen.WithDefaultLength(12), idgen.WithCharSet("abcdef0123456789")) 
if err != nil {
    return nil, fmt.Error("initializing id generator: %w", err)
}

// Generate IDs!
idA := g.NewID()
idB := g.NewID()
...

Contributing

Contribution guidelines can be found on our website.