Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaevor/go-nanoid
Nano ID for Go
https://github.com/jaevor/go-nanoid
go golang guid nanoid uuid
Last synced: 11 days ago
JSON representation
Nano ID for Go
- Host: GitHub
- URL: https://github.com/jaevor/go-nanoid
- Owner: jaevor
- License: gpl-3.0
- Created: 2022-06-26T02:18:29.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T10:37:31.000Z (13 days ago)
- Last Synced: 2024-06-03T12:47:28.389Z (13 days ago)
- Topics: go, golang, guid, nanoid, uuid
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jaevor/go-nanoid
- Size: 211 KB
- Stars: 426
- Watchers: 2
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- go-awesome - go-nanoid - NanoID 实现 (开源类库 / UUID)
README
# **go-nanoid**
[![Build Status](https://github.com/jaevor/go-nanoid/workflows/tests/badge.svg)](https://github.com/jaevor/go-nanoid/actions)
[![Build Status](https://github.com/jaevor/go-nanoid/workflows/lint/badge.svg)](https://github.com/jaevor/go-nanoid/actions)
[![GitHub Issues](https://img.shields.io/github/issues/jaevor/go-nanoid.svg)](https://github.com/jaevor/go-nanoid/issues)
[![Go Version](https://img.shields.io/github/go-mod/go-version/jaevor/go-nanoid?label=Go)](https://github.com/jaevor/go-nanoid/blob/master/go.mod)
[![Go Ref](https://pkg.go.dev/badge/github.com/jaevor/go-nanoid)](https://pkg.go.dev/github.com/jaevor/go-nanoid)[This module](https://pkg.go.dev/github.com/jaevor/go-nanoid) is a Go
implementation of [ai/nanoid](https://github.com/ai/nanoid).```
go get github.com/jaevor/go-nanoid
``````go
import (
"log"
"github.com/jaevor/go-nanoid"
)func main() {
gen, err := nanoid.Canonic()
if err != nil {
panic(err)
}id1 := gen()
log.Printf("ID 1: %s", id1) // eLySUP3NTA48paA9mLK3V// Makes sense to use CustomASCII since 0-9 is ASCII.
decenaryID, err := nanoid.CustomASCII("0123456789", 12)
if err != nil {
panic(err)
}id2 := decenaryID()
log.Printf("ID 2: %s", id2) // 817411560404
}
```# Note
This module's functions use an internal buffered slice of random bytes, and thus
also a mutex. This slight (but constant) overhead of memory per generator allows
it to be very efficient, but may not be ideal if you are only generating an ID
every now and then.# Security
- [Comparison of Nano ID and UUID (V4)](https://github.com/ai/nanoid/blob/main/README.md#comparison-with-uuid)
- [NanoID collision calculator](https://zelark.github.io/nano-id-cc/)
- [More](https://github.com/ai/nanoid/blob/main/README.md)## Benchmarks
All benchmarks & tests are in [nanoid_test.go](./nanoid_test.go).
These are all benchmarks of `nanoid.Standard(#)`
| # of characters & # of IDs | benchmark screenshot |
| -------------------------- | --------------------------------- |
| 8, ~21,800,000 ||
| 21, ~16,400,000 ||
| 36, ~11,500,000 ||
| 255, ~2,500,000 ||
## Credits & references
- [Original reference](https://github.com/ai/nanoid)
- [Older Go implementation of NanoID](https://github.com/matoous/go-nanoid)## License
[GNU General Public License v3.0](./LICENSE)