move IDGenerator interface to service package
This commit is contained in:
parent
9091ea8387
commit
9bffb2e39d
1 changed files with 1 additions and 1 deletions
21
service/ulid.go
Normal file
21
service/ulid.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package service
|
||||
|
||||
import "github.com/oklog/ulid/v2"
|
||||
|
||||
// IDGenerator produces unique identifiers for entities.
|
||||
type IDGenerator interface {
|
||||
// NewID generates a new unique identifier for entities.
|
||||
NewID() string
|
||||
}
|
||||
|
||||
// defaultIDGenerator generates ULIDs using crypto/rand entropy.
|
||||
type defaultIDGenerator struct{}
|
||||
|
||||
func (defaultIDGenerator) NewID() string {
|
||||
return ulid.Make().String()
|
||||
}
|
||||
|
||||
// DefaultIDGenerator returns the standard ULID-based generator.
|
||||
func DefaultIDGenerator() IDGenerator {
|
||||
return defaultIDGenerator{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue