testrunid.go 497 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "github.com/mattheath/goflake"
  4. "github.com/joaojeronimo/go-crc16"
  5. "fmt"
  6. "time"
  7. )
  8. func main() {
  9. // Create a new goflake with a worker id, these must be unique.
  10. hostid := uint32(crc16.Crc16([]byte("hostname1")))
  11. fmt.Println(hostid)
  12. if v, err := goflake.New( uint32(crc16.Crc16([]byte("hostname1"))) ) ; err !=nil {
  13. fmt.Println(err)
  14. }else{
  15. for i := 0; i < 10; i++ {
  16. id, _ := v.Generate()
  17. time.Sleep(time.Second)
  18. fmt.Println(id)
  19. }
  20. }
  21. }