Documentation
¶
Overview ¶
Package uid generates prefixed random identifiers for Wappiz resources.
The package provides two main functions for generating random strings: New for prefixed identifiers and [DNS1035] for DNS-compliant labels.
Security ¶
This package uses math/rand/v2 which is NOT cryptographically secure. The generated identifiers are predictable and MUST NOT be used for API keys, session tokens, or any security-sensitive purposes. Use crypto/rand directly for those cases.
Usage ¶
Generate a prefixed identifier:
id := uid.New(uid.RequestPrefix) // "req_k3n5p8x2"
Generate a DNS-1035 compliant label:
label := uid.DNS1035() // "k3n5p8x2" (starts with letter) label := uid.DNS1035(12) // "a9k2n5p8x3m7"
Prefixes ¶
Standard prefixes are defined as Prefix constants (RequestPrefix, APIPrefix) to make IDs self-descriptive. See prefix.go for the complete list.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New generates a prefixed random identifier.
The identifier consists of the prefix, an underscore separator, and random alphanumeric characters. Default random portion is 8 characters; pass a custom length to override.
Pass an empty prefix to generate an identifier without a prefix.
Uses math/rand/v2 which is NOT cryptographically secure. Do not use for API keys, tokens, or security-sensitive purposes.
func Secure ¶
Secure generates a cryptographically secure random identifier.
Uses crypto/rand for secure random generation. Use this for verification tokens, API keys, or any security-sensitive purposes.
The identifier consists of random alphanumeric characters. Default length is 24 characters; pass a custom length to override.