gonanoid

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 3 Imported by: 457

README

Go Nanoid

CI GoDoc Go Report Card GitHub issues License

This package is Go implementation of ai's nanoid!

Safe. It uses cryptographically strong random generator.

Compact. It uses more symbols than UUID (A-Za-z0-9_-) and has the same number of unique options in just 22 symbols instead of 36.

Fast. Nanoid is as fast as UUID but can be used in URLs.

There's also this alternative: https://github.com/jaevor/go-nanoid.

Install

Via go get tool

$ go get github.com/matoous/go-nanoid/v2

Usage

Generate ID

id, err := gonanoid.New()

Generate ID with a custom alphabet and length

id, err := gonanoid.Generate("abcde", 54)

Notice

If you use Go Nanoid in your project, please let me know!

If you have any issues, just feel free and open it in this repository, thanks!

Credits

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(alphabet string, size int) (string, error)

Generate is a low-level function to change alphabet and ID size.

func Must

func Must(l ...int) string

Must is the same as New but panics on error.

func MustGenerate

func MustGenerate(alphabet string, size int) string

MustGenerate is the same as Generate but panics on error.

func New

func New(l ...int) (string, error)

New generates secure URL-friendly unique ID. Accepts optional parameter - length of the ID to be generated (21 by default).

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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