-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (53 loc) · 1.77 KB
/
main.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
package main
import (
"fmt"
"io/ioutil"
"time"
"github.com/mylxsw/asteria/formatter"
"github.com/mylxsw/asteria/level"
"github.com/mylxsw/asteria/log"
"github.com/mylxsw/glacier/infra"
"github.com/mylxsw/glacier/starter/app"
"github.com/mylxsw/healthcheck/api"
"github.com/mylxsw/healthcheck/internal/alert"
"github.com/mylxsw/healthcheck/internal/config"
"github.com/mylxsw/healthcheck/internal/healthcheck"
"github.com/mylxsw/healthcheck/internal/scheduler"
)
var Version = "1.0"
var GitCommit = "5dbef13fb456f51a5d29464d"
func main() {
ins := app.Create(fmt.Sprintf("%s %s", Version, GitCommit), 3).WithShutdownTimeoutFlag(3 * time.Second)
ins.AddStringFlag("listen", "127.0.0.1:10101", "服务监听地址")
ins.AddStringFlag("healthcheck", "healthchecks.yaml", "健康检查配置文件路径")
ins.AddBoolFlag("debug", "是否使用调试模式")
ins.BeforeServerStop(func(resolver infra.Resolver) error {
return resolver.Resolve(func(c infra.FlagContext) {
if !c.Bool("debug") {
log.All().LogLevel(level.Info)
log.All().LogFormatter(formatter.NewJSONFormatter())
}
})
})
ins.Singleton(func(c infra.FlagContext) *healthcheck.GlobalConfig {
confData, err := ioutil.ReadFile(c.String("healthcheck"))
if err != nil {
panic(fmt.Errorf("read config file from %s failed: %v", c.String("healthcheck"), err))
}
// healthcheck
globalConf, err := healthcheck.ParseYamlConfig(confData)
if err != nil {
panic(fmt.Errorf("parse globalConfig failed: %v", err))
}
return globalConf
})
ins.Singleton(func(c infra.FlagContext) *config.Config {
return &config.Config{
Version: Version,
GitCommit: GitCommit,
Listen: c.String("listen"),
}
})
ins.Provider(scheduler.Provider{}, alert.Provider{}, api.Provider{})
app.MustRun(ins)
}