-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
73 lines (59 loc) · 1.79 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
67
68
69
70
71
72
73
package main
import (
"flag"
"log"
"os"
)
type Config struct {
VegaGRPCURL string
WalletURL string
BinanceWSURL string
WalletToken string
WalletPubkey string
VegaMarket string
BinanceMarket string
LPFee string
}
func parseFlags() *Config {
flag.Parse()
if vegaGRPCURL = getSetting(vegaGRPCURL, os.Getenv("VEGAMM_VEGA_GRPC_URL")); len(vegaGRPCURL) <= 0 {
vegaGRPCURL = defaultVegaGRPCURL
}
if walletURL = getSetting(walletURL, os.Getenv("VEGAMM_WALLET_URL")); len(walletURL) <= 0 {
walletURL = defaultWalletURL
}
if binanceWSURL = getSetting(binanceWSURL, os.Getenv("VEGAMM_BINANCE_WS_URL")); len(binanceWSURL) <= 0 {
binanceWSURL = defaultBinanceWSURL
}
if walletToken = getSetting(walletToken, os.Getenv("VEGAMM_WALLET_TOKEN")); len(walletToken) <= 0 {
log.Fatal("error: -wallet-token flag is required")
}
if walletPubkey = getSetting(walletPubkey, os.Getenv("VEGAMM_WALLET_PUBKEY")); len(walletPubkey) <= 0 {
log.Fatal("error: -wallet-pubkey flag is required")
}
if vegaMarket = getSetting(vegaMarket, os.Getenv("VEGAMM_VEGA_MARKET")); len(vegaMarket) <= 0 {
log.Fatal("error: -vega-market flag is required")
}
if binanceMarket = getSetting(binanceMarket, os.Getenv("VEGAMM_BINANCE_MARKET")); len(binanceMarket) <= 0 {
log.Fatal("error: -binance-market flag is required")
}
if lpFee = getSetting(lpFee, os.Getenv("VEGAMM_LP_FEE")); len(lpFee) <= 0 {
log.Fatal("error: -lp-fee flag is required")
}
return &Config{
VegaGRPCURL: vegaGRPCURL,
WalletURL: walletURL,
BinanceWSURL: binanceWSURL,
WalletToken: walletToken,
WalletPubkey: walletPubkey,
VegaMarket: vegaMarket,
BinanceMarket: binanceMarket,
LPFee: lpFee,
}
}
func getSetting(flag, env string) string {
if len(flag) <= 0 {
return env
}
return flag
}