Add package ulid

This commit is contained in:
Jan Bader 2016-12-20 11:40:12 +01:00
parent 2de8e46bf3
commit dafc477fe8

26
ulid/ulid.go Normal file
View 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)
}