-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (65 loc) · 2.05 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"fmt"
"github.com/b-harvest/metisian/log"
"github.com/b-harvest/metisian/metis"
"github.com/rs/zerolog"
"os"
)
var (
cfg *metis.Config
)
func init() {
var (
configFilePath string
configFileToken string
logLevel string
stateFile string
EnvConfigFilePath = "CONFIG_FILE_PATH"
EnvConfigFileToken = "CONFIG_TOKEN"
DefaultConfigFilePath = "config.toml"
)
flag.StringVar(&configFilePath, "config", DefaultConfigFilePath,
fmt.Sprintf("configuration toml file path you'll use. and also you can set this value through env %s.\n"+
"If both set, env value will be used.", EnvConfigFilePath))
flag.StringVar(&configFileToken, "config-token", "",
fmt.Sprintf("If you set this, it'll be use as Authorization Header with `Bearer $CONFIG_TOKEN`.\n"+
"you could also set this value with env %s.\n"+
"If both set, env value will be used.", EnvConfigFileToken))
flag.StringVar(&stateFile, "state", ".metisian-state.json", "file for storing state between restarts")
flag.StringVar(&logLevel, "log-level", "info", "log level you would show. (debug, info, warn, error...)")
flag.Parse()
if configFilePath == DefaultConfigFilePath && os.Getenv(EnvConfigFilePath) != "" {
configFilePath = os.Getenv(EnvConfigFilePath)
}
if configFileToken == "" && os.Getenv(EnvConfigFileToken) != "" {
configFileToken = os.Getenv(EnvConfigFileToken)
}
l, err := zerolog.ParseLevel(logLevel)
if err != nil {
panic(err)
}
zerolog.SetGlobalLevel(l)
cfg, err = metis.LoadConfig(configFilePath, configFileToken, stateFile)
if err != nil {
panic(err)
}
}
func main() {
client, err := metis.NewClient(cfg)
if err != nil {
panic(err)
}
defer client.Cancel()
go client.Run()
var seqAddrsMsg string
for n, seq := range client.GetSequencers() {
seqAddrsMsg = fmt.Sprintf("%s✅ [%15.15s] %s\n", seqAddrsMsg, n, seq.Address)
}
log.Info(fmt.Sprintf("Starting monitor metis sequencers...\n%s", seqAddrsMsg))
saved := make(chan interface{})
client.SaveOnExit(cfg.StateFile, saved)
<-client.Ctx.Done()
<-saved
}