Skip to content

garrettsparks/idgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

codecov Go Report Card Quality Gate Status

idgen

-- import "github.com/garrettsparks/idgen"

Package idgen uses crypt/rand to generate a random string of a given length.

Usage

const (
        // DefaultIDChars defines the default set of characters as alphanumeric plus uppercase.
        DefaultIDChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

        // DefaultIDLength defines the default ID length as 8.
        DefaultIDLength = 8
)

type IDBuilder

type IDBuilder struct {
}

IDBuilder is a builder for an ID.

func New

func New() *IDBuilder

New creates a new IDBuilder with a specified length.

func (*IDBuilder) BuildID

func (builder *IDBuilder) BuildID() string

BuildID builds an ID.

func (*IDBuilder) WithCharset

func (builder *IDBuilder) WithCharset(chars string) *IDBuilder

WithCharset sets the string of available characters for the builder to use when generating an ID. The default is alphanumeric plus uppercase.

func (*IDBuilder) WithLength

func (builder *IDBuilder) WithLength(length int) *IDBuilder

WithLength sets the length of the randomly generated ID. The default length is 8.

About

small library for crypto/rand string generation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages