budgeteer/ulid/ulid.go
2016-12-20 16:39:09 +01:00

29 lines
514 B
Go

package ulid
import (
"math/rand"
"time"
"git.javil.eu/jacob1123/budgeteer"
"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() budgeteer.ID {
id := ulid.MustNew(ulid.Timestamp(time.Now()), ug.entropy)
return budgeteer.ID(id)
}