ID generator returns a pointer to platform.ID now
parent
a5465f6416
commit
de66503de8
|
@ -12,10 +12,12 @@ func init() {
|
|||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// IDGenerator holds the ID generator.
|
||||
type IDGenerator struct {
|
||||
Generator *snowflake.Generator
|
||||
}
|
||||
|
||||
// NewIDGenerator creates a new ID generator.
|
||||
func NewIDGenerator() *IDGenerator {
|
||||
return &IDGenerator{
|
||||
// Maximum machine id is 1023
|
||||
|
@ -23,6 +25,8 @@ func NewIDGenerator() *IDGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *IDGenerator) ID() platform.ID {
|
||||
return platform.ID(g.Generator.Next())
|
||||
// ID returns a pointer to a generated ID.
|
||||
func (g *IDGenerator) ID() *platform.ID {
|
||||
id := platform.ID(g.Generator.Next())
|
||||
return &id
|
||||
}
|
||||
|
|
|
@ -10,7 +10,10 @@ import (
|
|||
func TestIDLength(t *testing.T) {
|
||||
gen := NewIDGenerator()
|
||||
id := gen.ID()
|
||||
if len(id.Encode()) != 16 {
|
||||
if id == nil {
|
||||
t.Fail()
|
||||
}
|
||||
if len(id.Encode()) != platform.IDLength {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue