id

package
v0.85.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

kit/id

github.com/vormadev/vorma/kit/id

Cryptographically random string ID generation with uniform character selection.

Import

import "github.com/vormadev/vorma/kit/id"

Quick Start

v, err := id.New(16) // default [0-9A-Za-z]

Custom charset:

numeric, err := id.New(8, "0123456789")

Batch generation:

values, err := id.NewMulti(12, 5)

Charset Rules

  • Optional charset argument count: at most one.
  • Charset length: 1..255.
  • Charset must be single-byte ASCII only.

Invalid charset input returns an error.

Length and Quantity

  • idLen is uint8 (0..255).
  • quantity is uint8 (0..255).
  • New(0, ...) returns "" with no error (after charset validation).
  • NewMulti(..., 0, ...) returns an empty slice.

Randomness and Bias

Generation uses crypto/rand plus rejection sampling so character distribution stays uniform even when charset size does not divide 256.

API Reference

  • func New(idLen uint8, optionalCharset ...string) (string, error)
  • func NewMulti(idLen uint8, quantity uint8, optionalCharset ...string) ([]string, error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(idLen uint8, optionalCharset ...string) (string, error)

New generates a cryptographically random string ID of the specified length. By default, IDs consist of mixed-case alphanumeric characters (0-9, A-Z, a-z). A single optional custom charset can be provided if you want to use different characters. The idLen parameter must be between 0 and 255 inclusive. If provided, the custom charset length must be between 1 and 255 inclusive.

func NewMulti

func NewMulti(idLen uint8, quantity uint8, optionalCharset ...string) ([]string, error)

NewMulti generates multiple cryptographically random string IDs of the specified length and quantity. By default, IDs consist of mixed-case alphanumeric characters (0-9, A-Z, a-z). A single optional custom charset can be provided if you want to use different characters. The idLen parameter must be between 0 and 255 inclusive.

Types

This section is empty.

Jump to

Keyboard shortcuts

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