-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.go
76 lines (63 loc) · 2.64 KB
/
setup.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
package main
import (
"flag"
"os"
"time"
"github.com/NickP005/go_mcminterface"
)
/*
* Creates if it doesn't exist the interface_settings.json file
*/
func Setup() {
}
/*
* Loads the flags and prepares the program accordingly
*/
func SetupFlags() bool {
solo_node := ""
flag.StringVar(&SETTINGS_PATH, "settings", "interface_settings.json", "Path to the interface settings file")
flag.StringVar(&TFILE_PATH, "tfile", "mochimo/bin/d/tfile.dat", "Path to node's tfile.dat file")
flag.StringVar(&TXCLEANFILE_PATH, "txclean", "mochimo/bin/d/txclean.dat", "Path to node's txclean.dat file")
flag.Float64Var(&SUGGESTED_FEE_PERC, "fp", 0.4, "The lower percentile of fees set in recent blocks")
flag.DurationVar(&REFRESH_SYNC_INTERVAL, "refresh_interval", 5*time.Second, "The interval in seconds to refresh the sync")
flag.IntVar(&Globals.LogLevel, "ll", 5, "Log level (1-5). Least to most verbose")
flag.StringVar(&solo_node, "solo", "", "Bypass settings and use a single node ip (e.g. 0.0.0.0")
flag.IntVar(&Globals.HTTPPort, "p", 8080, "Port to listen to")
flag.IntVar(&Globals.HTTPSPort, "ptls", 8443, "Port to listen to for TLS")
flag.IntVar(&go_mcminterface.Settings.DefaultPort, "np", 2095, "Port to connect to the node")
flag.BoolVar(&Globals.OnlineMode, "online", true, "Run in online mode")
flag.StringVar(&Globals.CertFile, "cert", "", "Path to SSL certificate file")
flag.StringVar(&Globals.KeyFile, "key", "", "Path to SSL private key file")
flag.BoolVar(&Globals.EnableIndexer, "indexer", false, "Enable the indexer")
flag.StringVar(&Globals.IndexerHost, "dbh", "localhost", "Indexer host")
flag.IntVar(&Globals.IndexerPort, "dbp", 3306, "Indexer port")
flag.StringVar(&Globals.IndexerUser, "dbu", "root", "Indexer user")
flag.StringVar(&Globals.IndexerPassword, "dbpw", "", "Indexer password")
flag.StringVar(&Globals.IndexerDatabase, "dbdb", "mochimo", "Indexer database")
flag.Parse()
// Check environment variables if flags are not set
if Globals.CertFile == "" {
Globals.CertFile = getEnv("MCM_CERT_FILE", "")
}
if Globals.KeyFile == "" {
Globals.KeyFile = getEnv("MCM_KEY_FILE", "")
}
// Enable HTTPS only if both cert and key are provided
Globals.EnableHTTPS = Globals.CertFile != "" && Globals.KeyFile != ""
if flag.Lookup("help") != nil {
flag.PrintDefaults()
return false
}
if solo_node != "" {
go_mcminterface.Settings.StartIPs = []string{solo_node}
go_mcminterface.Settings.ForceQueryStartIPs = true
}
return true
}
// Helper function to get environment variables with default value
func getEnv(key, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultValue
}