ids

package
v0.0.0-...-6a2234f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ids covers mainly ID generation

Index

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

func IsAllowed(id string, denylist Denylist) bool

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 Denylist

type Denylist = []string

func LoadDenylist

func LoadDenylist(filename string) (Denylist, error)

type Generator

type Generator interface {
	GenerateID() (string, error)
}

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL