diff --git a/example/example.go b/example/example.go index 16d4eb9..6e8adfe 100644 --- a/example/example.go +++ b/example/example.go @@ -2,13 +2,18 @@ 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) + fmt.Println(id) // 1537200202186752 sid := snowflake.ParseID(id) // SID { diff --git a/snowflake.go b/snowflake.go index cab2d38..9b5eb19 100644 --- a/snowflake.go +++ b/snowflake.go @@ -84,7 +84,7 @@ func SetStartTime(s time.Time) { panic("The start time cannot be a zero value") } - if s.After(time.Now()) { + if s.After(time.Now().UTC()) { panic("The s cannot be greater than the current millisecond") }