56 lines
1.8 KiB
Markdown
56 lines
1.8 KiB
Markdown
# Go Nanoid
|
|
|
|
[](https://github.com/matoous/go-nanoid/actions)
|
|
[](https://godoc.org/github.com/matoous/go-nanoid)
|
|
[](https://goreportcard.com/report/github.com/matoous/go-nanoid)
|
|
[](https://github.com/matoous/go-nanoid/issues)
|
|
[](https://github.com/matoous/go-nanoid/LICENSE)
|
|
|
|
This package is Go implementation of [ai's](https://github.com/ai) [nanoid](https://github.com/ai/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
|
|
|
|
``` bash
|
|
$ go get github.com/matoous/go-nanoid/v2
|
|
```
|
|
|
|
## Usage
|
|
|
|
Generate ID
|
|
|
|
``` go
|
|
id, err := gonanoid.New()
|
|
```
|
|
|
|
Generate ID with a custom alphabet and length
|
|
|
|
``` go
|
|
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
|
|
|
|
- [ai](https://github.com/ai) - [nanoid](https://github.com/ai/nanoid)
|
|
- icza - his tutorial on [random strings in Go](https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang)
|
|
|
|
## License
|
|
|
|
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|