Documentation
¶
Overview ¶
Package ids covers mainly ID generation
Index ¶
- Constants
- func IsAllowed(id string, denylist Denylist) bool
- func WithNanoIDCustomASCII(chars string) func(*NanoIDGenerator)
- func WithNanoIDDenylist(denylist []string) func(*NanoIDGenerator)
- func WithNanoIDLength(length int) func(*NanoIDGenerator)
- func WithNanoIDMaxAttempts(maxAttempts int) func(*NanoIDGenerator)
- type Denylist
- type Generator
- type NanoIDGenerator
Constants ¶
View Source
const ( // The alphabet that can make up an ID, every char should be safe for use in URLs without extra encoding NanoIDDefaultCharacters = "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" NanoIDDefaultLength = 10 // the default max number of attempts to generate an ID until it doesn't // match anything in the denylist NanoIDDefaultMaxAttempts = 10 )
Variables ¶
This section is empty.
Functions ¶
func IsAllowed ¶
IsAllowed returns false if the ID (normalised to lowecase) matches anything in the denylist, true otherwise.
func WithNanoIDCustomASCII ¶
func WithNanoIDCustomASCII(chars string) func(*NanoIDGenerator)
func WithNanoIDDenylist ¶
func WithNanoIDDenylist(denylist []string) func(*NanoIDGenerator)
func WithNanoIDLength ¶
func WithNanoIDLength(length int) func(*NanoIDGenerator)
WithNanoIDLength specifies a specific length for the generated Nano IDs. See https://zelark.github.io/nano-id-cc/ on length and collisions.
func WithNanoIDMaxAttempts ¶
func WithNanoIDMaxAttempts(maxAttempts int) func(*NanoIDGenerator)
WithNanoIDLength specifies the max number of attempts to generate an ID until it doesn't match anything in the denylist
Types ¶
type NanoIDGenerator ¶
type NanoIDGenerator struct {
// contains filtered or unexported fields
}
func NewNanoIDGenerator ¶
func NewNanoIDGenerator(options ...func(*NanoIDGenerator)) (*NanoIDGenerator, error)
func (*NanoIDGenerator) GenerateID ¶
func (g *NanoIDGenerator) GenerateID() (string, error)
Click to show internal directories.
Click to hide internal directories.