https://github.com/matoous/go-nanoid
Golang random IDs generator.
https://github.com/matoous/go-nanoid
golang nanoid unique-id uuid
Last synced: 2 months ago
JSON representation
Golang random IDs generator.
- Host: GitHub
- URL: https://github.com/matoous/go-nanoid
- Owner: matoous
- License: mit
- Created: 2017-09-12T16:51:21.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T00:25:05.000Z (4 months ago)
- Last Synced: 2025-04-23T17:17:43.144Z (3 months ago)
- Topics: golang, nanoid, unique-id, uuid
- Language: Go
- Homepage:
- Size: 85 KB
- Stars: 1,401
- Watchers: 8
- Forks: 61
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
> [!NOTE]
> There's little to no development on this repo, intentionally. It does what it needs to do. Bug reports are welcomed, features _might_ be implemented.
>
> If you are considering more heavy weight solution that integrates with UUIDs (supported by many databases) I would suggest you take a look at [typeid](https://github.com/sumup/typeid) or other equivalents.## 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) for more information.