bwmarrin / snowflake

A simple to use Go (golang) package to generate or parse Twitter snowflake IDs
BSD 2-Clause "Simplified" License
3.02k stars 374 forks source link

Use constants for bits, for easier changing #10

Closed freman closed 6 years ago

freman commented 7 years ago

We've got a fork of this where we change the number of node/host bits to 7, by adding some more constants the change is almost fully automagic.

bwmarrin commented 7 years ago

Hey great idea :) Looks good - but let me do a quick test of it to be safe :)

However I had a thought. Even with this you have to change the consts. Given your use case, what do you think about allowing these to be made public or providing setters? Then you wouldn't need to keep a fork of the lib?

freman commented 7 years ago

Hehe please double check my work, given how busy we've been I wouldn't be surprised if I made a simple oversight.

In our work, they're still constants, we never want to change them, we literally just changed nodeBits to 7 It'd cause chaos if everyone could change it depending on their mood for a given project (or series of microservices)

freman commented 7 years ago

Oh, after some sleep, I see what you're saying.

Yes, setters would be a good idea, just so long as the defaults remain compatible with the original right? :D

bwmarrin commented 7 years ago

Yeah, definitely keep the defaults the same, but this way you won't need to modify the code at all. You can just use a setter to make the changes you need for your project.