mirror of
https://github.com/godruoyi/go-snowflake.git
synced 2025-12-23 13:35:16 +00:00
27 lines
552 B
Go
27 lines
552 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/godruoyi/go-snowflake"
|
|
)
|
|
|
|
func main() {
|
|
// set starttime and machineID for the first time if you wan't to use the default value
|
|
snowflake.SetStartTime(time.Date(2021, 9, 1, 0, 0, 0, 0, time.UTC))
|
|
snowflake.SetMachineID(snowflake.PrivateIPToMachineID()) // testing, not to be used in production
|
|
|
|
id := snowflake.ID()
|
|
fmt.Println(id) // 1537200202186752
|
|
|
|
sid := snowflake.ParseID(id)
|
|
// SID {
|
|
// Sequence: 0
|
|
// MachineID: 0
|
|
// Timestamp: x
|
|
// ID: x
|
|
// }
|
|
fmt.Println(sid)
|
|
}
|