Update ID generator according to platform.ID
parent
09b7a4138f
commit
26cd66f165
|
|
@ -1,7 +1,6 @@
|
|||
package snowflake
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
|
@ -9,8 +8,6 @@ import (
|
|||
"github.com/influxdata/platform"
|
||||
)
|
||||
|
||||
// TODO: rename to id.go
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
|
@ -27,8 +24,5 @@ func NewIDGenerator() *IDGenerator {
|
|||
}
|
||||
|
||||
func (g *IDGenerator) ID() platform.ID {
|
||||
id := make(platform.ID, 8)
|
||||
i := g.Generator.Next()
|
||||
binary.BigEndian.PutUint64(id, i)
|
||||
return id
|
||||
return platform.ID(g.Generator.Next())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
func TestIDLength(t *testing.T) {
|
||||
gen := NewIDGenerator()
|
||||
id := gen.ID()
|
||||
if len(id) != 8 {
|
||||
if len(id.Encode()) != 16 {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ func TestToFromString(t *testing.T) {
|
|||
var clone platform.ID
|
||||
if err := clone.DecodeFromString(id.String()); err != nil {
|
||||
t.Error(err)
|
||||
} else if !bytes.Equal(id, clone) {
|
||||
} else if !bytes.Equal(id.Encode(), clone.Encode()) {
|
||||
t.Errorf("id started as %x but got back %x", id, clone)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue