osamingo / indigo Goto Github PK
View Code? Open in Web Editor NEWA distributed unique ID generator of using Sonyflake and encoded by Base58
License: MIT License
A distributed unique ID generator of using Sonyflake and encoded by Base58
License: MIT License
eg:
dateTmStr := "2017-10-11 16:00:00"
loc, _ := time.LoadLocation("Local")
dateTime, err := time.ParseInLocation("2006-01-02 15:04:05", dateTmStr, loc)
genHandle := indigo.New(nil, indigo.StartTime(dateTime), indigo.MachineID(1))
idStr, err := genHandle .NextID()
// 这idstr会是相同的id
eg:
my log show this( id generation in first time)
2020/03/05 16:45:31.579 [D] [*.go:42] new idstr: J6asGGvR1A
2020/03/05 16:45:31.579 [D] [.go:40] new global uniq id: J6asGGvR1A
(then generate an other id, log show the same as first one):
2020/03/05 16:45:31.579 [D] [.go:339] new token id: J6asGGvR1A
2020/03/05 16:45:31.579 [D] [.go:347] new token: J6asGGvR1A
question:
the implementation of unique id generator is not ok, as it produce same id in one node.
its' implementation need to check..
I am hoping to use this in some code for generating unique max 11 character IDs.
A couple of questions:
i) Can the library be used where different instances of a code, say in a Lambda Functions, need to get a unique ID, or there needs to be a running server, coordinating the IDs?
ii) I tried a small unit test:
g := indigo.New(nil, indigo.StartTime(time.Now()))
id1, err := g.NextID()
if err != nil {
t.Error("should be nil")
}
fmt.Println(id1)
id2, err := g.NextID()
if err != nil {
t.Error("should be nil")
}
fmt.Println(id2)
I was getting same values for different executions of the test:
=== RUN TestIndigoID
nvReu8adFt
nvReu8axjp=== RUN TestIndigoID
nvReu8adFt
nvReu8axjp
Another set of consecutive runs:
=== RUN TestIndigoID
2Uzir
2VLCn=== RUN TestIndigoID
2Uzir
2VLCn
Does this mean it starts from an initial value whenever there is a call toindigo.New
?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.