-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_provider.go
43 lines (36 loc) · 991 Bytes
/
service_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package hashing
import (
"github.com/goal-web/contracts"
"github.com/goal-web/supports/utils"
)
type ServiceProvider struct {
}
func (this ServiceProvider) Stop() {
}
func (this ServiceProvider) Start() error {
return nil
}
func (this ServiceProvider) Register(container contracts.Application) {
container.Singleton("hash", func(config contracts.Config) contracts.HasherFactory {
return &Factory{
config: config,
hashes: make(map[string]contracts.Hasher),
drivers: map[string]contracts.HasherProvider{
"bcrypt": func(config contracts.Fields) contracts.Hasher {
return &Bcrypt{
cost: utils.GetIntField(config, "cost", 14),
salt: utils.GetStringField(config, "salt"),
}
},
"md5": func(config contracts.Fields) contracts.Hasher {
return &Md5{
salt: utils.GetStringField(config, "salt"),
}
},
},
}
})
container.Singleton("hashing", func(factory contracts.HasherFactory) contracts.Hasher {
return factory
})
}