-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
87 lines (80 loc) · 2.36 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
84
85
86
87
package main
import (
"flag"
"fmt"
"os"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/bnb-chain/greenfield-relayer/app"
"github.com/bnb-chain/greenfield-relayer/config"
"github.com/bnb-chain/greenfield-relayer/logging"
)
func initFlags() {
flag.String(config.FlagConfigPath, "", "config file path")
flag.String(config.FlagConfigType, "", "config type, local_private_key or aws_private_key")
flag.String(config.FlagConfigAwsRegion, "", "aws region")
flag.String(config.FlagConfigAwsSecretKey, "", "aws secret key")
flag.String(config.FlagConfigPrivateKey, "", "relayer private key")
flag.String(config.FlagConfigBlsPrivateKey, "", "relayer bls private key")
flag.String(config.FlagConfigDbPass, "", "relayer db password")
flag.String(config.FlagConfigDbUsername, "", "relayer db username")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
panic(err)
}
}
func printUsage() {
fmt.Print("usage: ./greenfield-relayer --config-type local --config-path configFile\n")
fmt.Print("usage: ./greenfield-relayer --config-type aws --aws-region awsRegin --aws-secret-key awsSecretKey\n")
}
func main() {
var (
cfg *config.Config
configType, configFilePath string
)
initFlags()
configType = viper.GetString(config.FlagConfigType)
if configType == "" {
configType = os.Getenv(config.ConfigType)
}
if configType != config.AWSConfig && configType != config.LocalConfig {
printUsage()
return
}
if configType == config.AWSConfig {
awsSecretKey := viper.GetString(config.FlagConfigAwsSecretKey)
if awsSecretKey == "" {
printUsage()
return
}
awsRegion := viper.GetString(config.FlagConfigAwsRegion)
if awsRegion == "" {
printUsage()
return
}
configContent, err := config.GetSecret(awsSecretKey, awsRegion)
if err != nil {
fmt.Printf("get aws config error, err=%s", err.Error())
return
}
cfg = config.ParseConfigFromJson(configContent)
} else {
configFilePath = viper.GetString(config.FlagConfigPath)
if configFilePath == "" {
configFilePath = os.Getenv(config.ConfigFilePath)
if configFilePath == "" {
printUsage()
return
}
}
cfg = config.ParseConfigFromFile(configFilePath)
}
if cfg == nil {
panic("failed to get configuration")
}
logging.InitLogger(&cfg.LogConfig)
app.NewApp(cfg).Start()
select {}
}