A Go version of Uid-Generator , a Snowflake based unique ID generator.
Work in progress.
- BaseGenerator(DefaultGenerator)
- CachedGenerator
Welcome to open issues or pull requests to help me complete this project.
All code logic is the same as the Java version, but the following differences:
- WorkerIDAssigner is not implemented, so you need to assign worker id by yourself.
- Difference between Goroutines and Java Threads
- ...
import "github.com/FAWC438/uid-generator-go"
...
There is a demo to show how to use BaseGenerator
.
package test
import (
"fmt"
"uid-generator-go/generator"
)
func Test() {
var gen generator.UidGenerator
gen = generator.BaseGeneratorConstructor()
uid, e := gen.GetUID()
if e != nil {
fmt.Println(e)
return
}
fmt.Println(gen.ParseUID(uid))
}
Run this test and get your first awesome uid!