bwmarrin / snowflake

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

Support decode id #22

Closed axetroy closed 4 years ago

axetroy commented 4 years ago
func DecodeString (id string) (*Node, error) {
  // decode
}
bwmarrin commented 4 years ago

Can you give me some more context of what you're wanting?

axetroy commented 4 years ago

In some cases, we only have ID string

We need to know if it is a valid ID and which node this ID was generated from and when

bwmarrin commented 4 years ago

What format is the ID in though. "string" is a bit ambiguous.

Is it a string of numbers like "8217397129123" or some other format?

Have you tried using https://github.com/bwmarrin/snowflake/blob/master/snowflake.go#L169 ? If it's a string of numbers, you can convert that into an int64 easily enough, then parse it with that function. After doing that, you can use the library to return the node.

axetroy commented 4 years ago

@bwmarrin I see. Thx.