-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (41 loc) · 1.41 KB
/
config.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
46
47
48
package config
import "log"
type Config struct {
Application *Application `mapstructure:"application" json:"application" yaml:"application"`
Database *Database `json:"database" yaml:"database"`
Databases *map[string]*Database `json:"databases" yaml:"databases"`
Logger *Logger `mapstructure:"logger" json:"logger" yaml:"logger"`
Cache *Cache `mapstructure:"cache" yaml:"cache" json:"cache"`
Filesystem *Filesystem `mapstructure:"filesystem" json:"mysql" yaml:"filesystem"`
Queue *Queue `json:"queue" yaml:"queue"`
Locker *Locker `json:"locker" yaml:"locker"`
JWT *Jwt `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
Casbin *Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
Extend interface{} `yaml:"extend"`
//
opts setOptions
}
func (c *Config) OnChange() {
//c.init()
log.Println("config change and reload")
}
//多db改造
func (c *Config) multiDatabase() {
if len(*c.Databases) == 0 {
*c.Databases = map[string]*Database{
"*": c.Database,
}
}
}
func (c *Config) runCallback() {
for _, callback := range c.opts.callbacks {
callback()
}
}
func (c *Config) init() {
c.Logger.Setup()
c.multiDatabase()
//调用回调函数
c.runCallback()
}