budgeteer/ulid/ulid.go
2016-12-20 11:40:12 +01:00

27 lines
446 B
Go

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)
}