-- import "github.com/garrettsparks/idgen"
Package idgen uses crypt/rand to generate a random string of a given length.
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 struct {
}
IDBuilder is a builder for an ID.
func New() *IDBuilder
New creates a new IDBuilder with a specified length.
func (builder *IDBuilder) BuildID() string
BuildID builds an ID.
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 (builder *IDBuilder) WithLength(length int) *IDBuilder
WithLength sets the length of the randomly generated ID. The default length is 8.