gonanoid

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: MIT Imports: 4 Imported by: 153

README

Go Nanoid

Build Status Build Status 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.

Install

Via go get tool

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

Usage

Generate ID

id, err := gonanoid.Nanoid()

Generate ID with custom alphabet and length

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

Testing

$ go test

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(rawAlphabet string, size int) (string, error)

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

func ID added in v1.3.0

func ID(l int) (string, error)

ID provides more golang idiomatic interface for generating IDs. Calling ID is shorter yet still clear `gonanoid.ID(20)` and it requires the lengths parameter by default.

func MustGenerate added in v1.5.0

func MustGenerate(rawAlphabet string, size int) string

MustGenerate is the same as Generate but panics on error.

func MustID added in v1.5.0

func MustID(l int) string

MustID is the same as ID but panics on error.

func Nanoid

func Nanoid(param ...int) (string, error)

Nanoid generates secure URL-friendly unique ID.

Types

type Generator

type Generator func([]byte) (int, error)

Generator function

var BytesGenerator Generator = rand.Read

BytesGenerator is the default bytes generator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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