| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/kankanreno/go-snowflake" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | func main() { |
| 10 | // set starttime and machineID for the first time if you wan't to use the default value |
| 11 | snowflake.SetStartTime(time.Date(1955, 1, 1, 0, 0, 0, 0, time.UTC)) |
| 12 | snowflake.SetMachineID(snowflake.PrivateIPToMachineID() % (snowflake.MaxMachineID + 1)) // testing, not to be used in production |
| 13 | |
| 14 | id := snowflake.ID() |
| 15 | fmt.Println(id) |
| 16 | // 9007199254740992 js max integer |
| 17 | // 496286021178368 4-bit machine id (unset), start 2008 |
| 18 | // 545487571292160 6-bit machine id (unset), start 2020 |
| 19 | // 545489678665664 6-bit machine id ( set), start 2020 |
| 20 | // 2096606852595712 6-bit machine id (unset), start 2008 |
| 21 | // 8947297216425984 6-bit machine id (unset), start 1955 |
| 22 | |
| 23 | sid := snowflake.ParseID(id) |
| 24 | // SID { |
| 25 | // Sequence: 0 |
| 26 | // MachineID: 0 |
| 27 | // Timestamp: x |
| 28 | // ID: x |
| 29 | // } |
| 30 | fmt.Println(sid) |
| 31 | } |