Documentation ¶
Overview ¶
Package nanoid provides fast and convenient unique string generator.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // DefaultAlphabet is the default alphabet for Nano ID. DefaultAlphabet = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" // DefaultSize is the default size for Nano ID. DefaultSize = 21 )
Variables ¶
This section is empty.
Functions ¶
func FormatString ¶
func FormatString(generateRandomBuffer BytesGenerator, alphabet string, size int) (string, error)
FormatString generates a random string based on BytesGenerator, alphabet and size.
Example ¶
alphabet := nanoid.DefaultAlphabet size := nanoid.DefaultSize // generateBytesBuffer returns random bytes buffer generateBytesBuffer := func(step int) ([]byte, error) { buffer := make([]byte, step) if _, err := rand.Read(buffer); err != nil { return nil, err } return buffer, nil } id, err := nanoid.FormatString(generateBytesBuffer, alphabet, size) if err != nil { log.Fatalln(err) } fmt.Println(id)
Output:
func GenerateString ¶
GenerateString generates a random string based on alphabet and size.
Example ¶
alphabet := nanoid.DefaultAlphabet size := nanoid.DefaultSize id, err := nanoid.GenerateString(alphabet, size) if err != nil { log.Fatalln(err) } fmt.Println(id)
Output:
Types ¶
type BytesGenerator ¶
BytesGenerator represents random bytes buffer.
Click to show internal directories.
Click to hide internal directories.