diff --git a/ulid/ulid.go b/ulid/ulid.go new file mode 100644 index 0000000..ba32639 --- /dev/null +++ b/ulid/ulid.go @@ -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) +}