-
Notifications
You must be signed in to change notification settings - Fork 1
/
appconfig.go
66 lines (54 loc) · 1.57 KB
/
appconfig.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
package conf
import (
"github.com/spf13/viper"
)
// AppConfig defines a structure to store app config data
// at present all config is mapped to Coins array
type AppConfig struct {
Coins []CoinData `json:"coins"`
}
// Coins defines properties of active coin
type CoinData struct {
Name string `json:"name"`
CurrencyCode string `json:"currencyCode"`
LibPath string `json:"libPath"`
DataDir string `json:"dataDir"`
DaemonHeartbeat int `json:"daemonHeartbeat"`
DaemonVersion string `json:"daemonVersion"`
WindowsDaemonName string `json:"windowsDaemonName"`
DarwinDaemonName string `json:"darwinDaemonName"`
LatestReleaseAPI string `json:"latestReleaseApi"`
ReleaseAPI string `json:"ReleaseApi"`
LivePort int `json:"livePort"`
TestNetPort int `json:"testnetPort"`
UseTestNet bool `json:"useTestNet"`
IndexTransactions bool `json:"indexTransactions"`
}
// StartConfigManager sets up the ticker loop to load app config
//func StartConfigManager() {
// ticker := time.NewTicker(time.Millisecond * 500)
// go func() {
// for range ticker.C {
// LoadAppConfig()
// }
// }()
//}
// LoadAppConfig sets up viper, reads and parses app config
func LoadAppConfig() error {
viper.SetConfigName("app-config")
viper.AddConfigPath("./")
viper.AddConfigPath("./app")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
return err
}
// parse out the config
var appConfig = AppConfig{}
err = viper.Unmarshal(&appConfig)
if err != nil {
return err
}
AppConf = appConfig
return nil
}