add hash ids provider
This commit is contained in:
23
providers/hashids/hashids.go
Normal file
23
providers/hashids/hashids.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package hashids
|
||||
|
||||
import (
|
||||
"github.com/rogeecn/atom/container"
|
||||
"github.com/rogeecn/atom/providers/log"
|
||||
"github.com/rogeecn/atom/utils/opt"
|
||||
|
||||
"github.com/speps/go-hashids/v2"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
o := opt.New(opts...)
|
||||
var config Config
|
||||
if err := o.UnmarshalConfig(&config); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return container.Container.Provide(func() (*hashids.HashID, error) {
|
||||
return hashids.NewWithData(&hashids.HashIDData{
|
||||
MinLength: int(config.MinLength),
|
||||
Salt: config.Salt,
|
||||
})
|
||||
}, o.DiOptions()...)
|
||||
}
|
||||
Reference in New Issue
Block a user