NewNanoID
Overview
NewNanoID returns a URL-safe ID using the default nanoid alphabet.
If you are coming from Node.js, the closest pattern is nanoid(size).
Signature
go
func NewNanoID(size int) (string, error)Compare: Node.js · Standard Go · gox
js
nanoid();go
// generate random URL-safe stringgo
import "github.com/sahilkhaire/gox/id"
id := id.NewNanoID(21)Example
go
import "github.com/sahilkhaire/gox/id"
id := id.NewNanoID(21)Tips
Import github.com/sahilkhaire/gox/id and call NewNanoID directly. See the comparison below for the standard library equivalent.
Standard library alternative
gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.