Add package ulid
This commit is contained in:
parent
2de8e46bf3
commit
dafc477fe8
26
ulid/ulid.go
Normal file
26
ulid/ulid.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package ulid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/oklog/ulid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UlidGenerator struct {
|
||||||
|
time time.Time
|
||||||
|
entropy *rand.Rand
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGenerator() (*UlidGenerator, error) {
|
||||||
|
t := time.Time{}
|
||||||
|
ug := &UlidGenerator{
|
||||||
|
time: t,
|
||||||
|
entropy: rand.New(rand.NewSource(t.UnixNano())),
|
||||||
|
}
|
||||||
|
return ug, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ug *UlidGenerator) New() ulid.ULID {
|
||||||
|
return ulid.MustNew(ulid.Timestamp(ug.time), ug.entropy)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user