add hasher
This commit is contained in:
@@ -18,6 +18,7 @@ func DefaultProvider() container.ProviderContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Alphabet string
|
||||||
Salt string
|
Salt string
|
||||||
MinLength uint
|
MinLength uint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,21 @@ func Provide(opts ...opt.Option) error {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
return container.Container.Provide(func() (*hashids.HashID, error) {
|
return container.Container.Provide(func() (*hashids.HashID, error) {
|
||||||
return hashids.NewWithData(&hashids.HashIDData{
|
data := hashids.NewData()
|
||||||
MinLength: int(config.MinLength),
|
data.MinLength = int(config.MinLength)
|
||||||
Salt: config.Salt,
|
if data.MinLength == 0 {
|
||||||
})
|
data.MinLength = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Salt = config.Salt
|
||||||
|
if data.Salt == "" {
|
||||||
|
data.Salt = "default-salt-key"
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Alphabet != "" {
|
||||||
|
data.Alphabet = config.Alphabet
|
||||||
|
}
|
||||||
|
|
||||||
|
return hashids.NewWithData(data)
|
||||||
}, o.DiOptions()...)
|
}, o.DiOptions()...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user