-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.go
66 lines (53 loc) · 1.39 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package glacier
import (
"github.com/mylxsw/glacier/log"
"strings"
"time"
"github.com/mylxsw/glacier/infra"
"github.com/mylxsw/go-utils/str"
)
const (
// ShutdownTimeoutOption 优雅停机超时时间命令行选型名称
ShutdownTimeoutOption = "shutdown-timeout"
)
// Config 框架级配置
type Config struct {
ShutdownTimeout time.Duration `json:"shutdown_timeout"`
}
func (c Config) String() string {
return "[" + "shutdown_timeout: " + c.ShutdownTimeout.String() + "]"
}
// ConfigLoader 框架级配置实例创建
func ConfigLoader(c infra.FlagContext) *Config {
config := &Config{}
config.ShutdownTimeout = c.Duration(ShutdownTimeoutOption)
if config.ShutdownTimeout.Microseconds() == 0 {
config.ShutdownTimeout = 15 * time.Second
}
if infra.DEBUG {
log.Debugf("[glacier] framework config loaded: %v", config.String())
}
return config
}
// IsGlacierModuleLog 判断模块名称是否是 Glacier 框架内部模块
func IsGlacierModuleLog(module string) bool {
if module == "glacier" {
return true
}
if strings.HasPrefix(module, "github.com.mylxsw") {
return str.HasPrefixes(module, []string{
"github.com.mylxsw.glacier",
"github.com.mylxsw.graceful",
})
}
if strings.HasPrefix(module, "g.c.m") {
return str.HasPrefixes(module, []string{
"g.c.m.glacier",
"g.c.m.graceful",
"g.c.m.g.event",
"g.c.m.g.scheduler",
"g.c.m.g.web",
})
}
return false
}