Documentation ¶
Overview ¶
Package nanoid provides a simple API to generate short, unique IDs.
Installation:
go get github.com/9ssi7/nanoid
Usage:
import "github.com/9ssi7/nanoid" id, err := nanoid.New() if err != nil { log.Fatal(err) }
Custom Length ID:
id, err := nanoid.NewWithLength(nanoid.LengthMedium) if err != nil { log.Fatal(err) }
Validating ID:
if !nanoid.Validate(id) { log.Fatal("Invalid ID") }
Benchmark Results:
goos: linux goarch: amd64 pkg: github.com/9ssi7/nanoid cpu: 12th Gen Intel(R) Core(TM) i7-12700H BenchmarkNanoID BenchmarkNanoID-20 1240796 933.8 ns/op BenchmarkGoogleUUID BenchmarkGoogleUUID-20 1312452 903.1 ns/op
Security:
NanoID uses crypto/rand for generating secure random IDs, reducing the likelihood of collision. However, the users should consider the trade-off between ID length and collision probability.
License:
Apache-2.0 License
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustNew ¶
func MustNew() string
MustNew returns a new random ID. It panics if any error occurs.
func NewWithLength ¶
NewWithLength returns a new random ID with custom length.
Types ¶
Click to show internal directories.
Click to hide internal directories.