-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
executable file
·53 lines (42 loc) · 1.14 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
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
func init() {
path := flag.String("config", "config.yaml", "-config=<config path>")
flag.Parse()
readAndMap(*path)
}
// Config struct for the app config
type Config struct {
ContractAddress string `yaml:"contract_address"`
PrivateKeyPath string `yaml:"private_key_path"`
PrivateKeyPassphrase string `yaml:"private_key_passphrase"`
NodeAddress string `yaml:"node_address"`
MaxGasLimit uint64 `yaml:"max_gas_limit"`
RecipientsCSVPath string `yaml:"recipients_csv_path"`
BatchSize int `yaml:"batch_size"`
NumberOfTokens string `yaml:"number_of_tokens"`
}
var config *Config
// GetConfig function will return instance of Config
func GetConfig() *Config {
return config
}
func readAndMap(path string) {
if _, err := os.Stat(path); err != nil {
log.Fatalf("config [%s] is not readable or doesn't exists!", path)
}
log.Printf("Reading config [%s].", path)
bytes, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalln(err)
}
if err := yaml.Unmarshal(bytes, &config); err != nil {
log.Fatalln(err)
}
}