func main() {
// Create a new Node with a Node number of 1
node, err := snowflake.NewNode(1)
if err != nil {
fmt.Println(err)
return
}
// Generate a snowflake ID.
id := node.Generate()
// Print out the ID in a few different ways.
fmt.Println(id)
fmt.Println(id.Base64())
b := id.IntBytes()
fmt.Println(base64.StdEncoding.EncodeToString(b[:]))
}
dig into souce, i found that base64 method use string representation of int64 for encoding, which make no sense:
// Base64 returns a base64 string of the snowflake ID
func (f ID) Base64() string {
return base64.StdEncoding.EncodeToString(f.Bytes())
}
// Bytes returns a byte slice of the snowflake ID
func (f ID) Bytes() []byte {
return []byte(f.String())
}
result:
dig into souce, i found that base64 method use string representation of int64 for encoding, which make no sense:
it only make representation much longer.