/
config.go
91 lines (75 loc) · 2.7 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package config
import (
"flag"
"fmt"
"github.com/spf13/viper"
)
// logger/logger.go can't be used here to log,
// since logger.go itself depends on the config
// to read `log.enableTrace`.
func init() {
// do not try to load a config file when running tests
if flag.Lookup("test.v") != nil {
return
}
setDefaults()
viper.SetConfigType("toml")
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
fmt.Println("ERROR: Error reading config file: ", err)
}
}
func setDefaults() {
viper.SetDefault("redis.host", "localhost")
viper.SetDefault("redis.connection", "redis")
viper.SetDefault("bitcoind.rest.protocol", "http")
viper.SetDefault("bitcoind.rest.host", "localhost")
viper.SetDefault("bitcoind.rest.port", "8332")
viper.SetDefault("bitcoind.rest.responseTimeout", 30)
viper.SetDefault("bitcoind.jsonrpc.protocol", "http")
viper.SetDefault("bitcoind.jsonrpc.host", "localhost")
viper.SetDefault("bitcoind.jsonrpc.port", "8332")
viper.SetDefault("bitcoind.jsonrpc.responseTimeout", 30)
viper.SetDefault("mempool.enable", false)
viper.SetDefault("mempool.fetchInterface", "REST")
viper.SetDefault("mempool.callSaveMempool", true)
viper.SetDefault("mempool.processing.processCurrentMempool", false)
viper.SetDefault("mempool.processing.processHistoricalMempool", false)
viper.SetDefault("mempool.processing.processTransactionStats", false)
viper.SetDefault("mempool.fetchInterval", 60)
viper.SetDefault("feeratefetcher.enable", false)
viper.SetDefault("feeratefetcher.fetchInterval", 180)
viper.SetDefault("log.enableTrace", false)
viper.SetDefault("log.colorizeOutput", true)
viper.SetDefault("zmq.enable", false)
viper.SetDefault("zmq.host", "localhost")
viper.SetDefault("zmq.port", 28332)
viper.SetDefault("zmq.subscribeTo.rawTx", false)
viper.SetDefault("zmq.subscribeTo.rawBlock", false)
viper.SetDefault("zmq.subscribeTo.hashTx", false)
viper.SetDefault("zmq.subscribeTo.hashBlock", false)
viper.SetDefault("zmq.saveMempoolEntries.enable", false) // saves mempool entries to a SQLite database
viper.SetDefault("zmq.saveMempoolEntries.dbPath", "/tmp/mempool-entries.sqlite")
}
// GetInt returns a config property as int
func GetInt(property string) int {
result := viper.GetInt(property)
if result == 0 {
fmt.Println("WARN: Property " + property + " is 0. Is this not set?")
}
return result
}
// GetString returns a config property as string
func GetString(property string) string {
result := viper.GetString(property)
if result == "" {
fmt.Println("WARN: Property " + property + " is \"\". Is this not set?")
}
return result
}
// GetBool returns a config property as bool
func GetBool(property string) bool {
return viper.GetBool(property)
}