-
Notifications
You must be signed in to change notification settings - Fork 19
/
configuration.go
73 lines (62 loc) · 2.18 KB
/
configuration.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 (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)
//MinerConfig struct for json parse
type MinerConfig struct {
Name string // NAME
Pin string // PIN-NUMBER OF GPIO
IP string // IP ADDRESS
Info string // ADDITIONAL INFO
}
//ConfigurationFile struct to parse config.json
type ConfigurationFile struct {
WaitSeconds int // Period of the timer checks in seconds
StartupCheck bool // Check miners on startup
Log bool //Enable or disable logging
RemoteNotify bool //Remote notification telegram,pushover & etc
TgBotActivate bool //Enable or disable Telegram bot
TgAPIKey string //Telegram Api key for bot communicationg
TgAdminUserName string //Telegram Username which will control the bot
Pushover bool //Enable or disable Pushover notifications
PushoverToken string //Pushover access token
PushoverUser string //Pushover user token
Miners []MinerConfig // An array of the
}
//Config is the global Config variable
var Config ConfigurationFile
//ReadConfig - read and parse the config file
func ReadConfig() (configFile ConfigurationFile) {
//get binary dir
//os.Args doesn't work the way we want with "go run". You can use next line
//for local dev, but use the original for production.
dir, err := filepath.Abs("./")
//dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
log.Notice("Reading file config.json...")
file := dir + "/config.json"
configFileContent, err := ioutil.ReadFile(file)
if err != nil {
log.Error("Trying to read file config.json, but:", err)
os.Exit(1)
}
log.Notice("Parsing configuration file...")
err = json.Unmarshal(configFileContent, &configFile)
if err != nil {
log.Error("Parsing JSON content, but:", err)
os.Exit(2)
}
log.Notice("Timer (time in seconds):", configFile.WaitSeconds)
log.Notice("Found miner configurations:", len(configFile.Miners))
if configFile.Pushover == true {
log.Notice("Pushover notification is ENABLED")
log.Notice("Pushover Token:", configFile.PushoverToken)
log.Notice("Pushover User:", configFile.PushoverUser)
}
return
}