Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osaminGo/indiGo
A distributed unique ID generator of using Sonyflake and encoded by Base58
https://github.com/osaminGo/indiGo
base58 go id identity snowflake sonyflake
Last synced: 18 days ago
JSON representation
A distributed unique ID generator of using Sonyflake and encoded by Base58
- Host: GitHub
- URL: https://github.com/osaminGo/indiGo
- Owner: osamingo
- License: mit
- Created: 2016-08-31T14:17:45.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T15:43:55.000Z (over 1 year ago)
- Last Synced: 2024-07-31T01:27:28.344Z (3 months ago)
- Topics: base58, go, id, identity, snowflake, sonyflake
- Language: Go
- Homepage:
- Size: 54.7 KB
- Stars: 109
- Watchers: 1
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Indigo
[![GitHub Actions](https://github.com/osamingo/indigo/workflows/CI/badge.svg?branch=master)](https://github.com/osamingo/indigo/actions?query=workflow%3ACI+branch%3Amaster)
[![codecov](https://codecov.io/gh/osamingo/indigo/branch/master/graph/badge.svg)](https://codecov.io/gh/osamingo/indigo)
[![Go Report Card](https://goreportcard.com/badge/osamingo/indigo)](https://goreportcard.com/report/osamingo/indigo)
[![codebeat badge](https://codebeat.co/badges/3885a5d8-7db0-4162-970a-577a1bf54199)](https://codebeat.co/projects/github-com-osamingo-indigo)
[![Maintainability](https://api.codeclimate.com/v1/badges/44865a174db0fad61812/maintainability)](https://codeclimate.com/github/osamingo/indigo/maintainability)
[![GoDoc](https://godoc.org/github.com/osamingo/indigo?status.svg)](https://godoc.org/github.com/osamingo/indigo)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/osamingo/indigo/master/LICENSE)## About
- A distributed unique ID generator of using Sonyflake and encoded by Base58.
- ID max length is 11 characters by unsigned int64 max value.
- An Encoder can change your original encoder ;)## Install
```shell
$ go get github.com/osamingo/indigo@latest
```## Usage
```go
package mainimport (
"log"
"sync"
"time""github.com/osamingo/indigo"
)var g *indigo.Generator
func init() {
t := time.Unix(1257894000, 0) // 2009-11-10 23:00:00 UTC
g = indigo.New(nil, indigo.StartTime(t))
_, err := g.NextID()
if err != nil {
log.Fatalln(err)
}
}func main() {
wg := sync.WaitGroup{}
wg.Add(100)
for i := 0; i < 100; i++ {
go func() {
defer wg.Done()
id, err := g.NextID()
if err != nil {
log.Fatalln(err)
} else {
log.Println("ID:", id)
}
}()
}wg.Wait()
}
```## Benchmark
```
# Machine: MacBook Pro (14-inch, 2021)
# CPU : Apple M1 Pro
# Memory : 32 GBgoos: darwin
goarch: arm64
pkg: github.com/osamingo/indigo
BenchmarkGenerator_NextID-10 30079 39191 ns/op 7 B/op 1 allocs/op
PASS
```## Bibliography
- [Sonyflake](https://github.com/sony/sonyflake) - A distributed unique ID generator inspired by Twitter's Snowflake.
- [Base58](https://en.wikipedia.org/wiki/Base58) - Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text.## License
Released under the [MIT License](https://github.com/osamingo/indigo/blob/master/LICENSE).