Awesome Go

indigo

CategoryMiscellaneous
SubcategoryUncategorized
Stars0

Distributed unique ID generator of using Sonyflake and encoded by Base58

About indigo

Indigo

CI codecov Go Report Card codebeat badge Maintainability GoDoc GitHub 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

$ go get github.com/osamingo/indigo@latest

Usage

package main

import (
	"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 GB

goos: darwin
goarch: arm64
pkg: github.com/osamingo/indigo
BenchmarkGenerator_NextID-10        30079       39191 ns/op        7 B/op     1 allocs/op
PASS

Bibliography

  • Sonyflake - A distributed unique ID generator inspired by Twitter's Snowflake.
  • 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.

Frequently Asked Questions

What is indigo?

indigo is a Miscellaneous library for the Go programming language. Distributed unique ID generator of using Sonyflake and encoded by Base58

How do I install indigo?

Install indigo with the Go module system using `go get osamingo/indigo`. Check the repository for the current installation instructions.

What category does indigo belong to?

indigo is listed under Miscellaneous, specifically Uncategorized.

← Back to Uncategorized