-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.go
45 lines (37 loc) · 1.08 KB
/
module.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
44
45
package redis
import (
"github.com/farseer-go/cache"
"github.com/farseer-go/fs/configure"
"github.com/farseer-go/fs/container"
"github.com/farseer-go/fs/core"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/fs/modules"
)
type Module struct {
}
func (module Module) DependsModule() []modules.FarseerModule {
return []modules.FarseerModule{cache.Module{}}
}
func (module Module) PreInitialize() {
container.Register(func() cache.ICache { return &cacheInRedis{} }, "redis")
}
func (module Module) Initialize() {
redisConfigs := configure.GetSubNodes("Redis")
for name, configString := range redisConfigs {
Register(name, configString)
}
}
// Register 注册Redis实例
func Register(name string, configString any) {
config := configure.ParseString[redisConfig](configString.(string))
if config.Server == "" {
_ = flog.Error("Redis配置缺少Server节点")
return
}
// 注册实例
container.Register(func() IClient {
return newClient(config)
}, name)
// 注册健康检查
container.RegisterInstance[core.IHealthCheck](&healthCheck{name: name}, "redis_"+name)
}