29 lines
514 B
Go
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)
|
|
}
|