- Add debug server listen address and port configuration in config.json and config.go - Update main.go to use debug config values when in debug mode - Add logging for monitor add/remove commands in commandParse.go
45 lines
933 B
Go
45 lines
933 B
Go
package main
|
|
|
|
|
|
import (
|
|
"Watchdog_Linux-systemd/postLog"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var Config struct {
|
|
DebugMode bool `json:"debugMode"`
|
|
Debug struct {
|
|
ListenAddr string `json:"listenAddr"`
|
|
ListenPort int `json:"listenPort"`
|
|
} `json:"debug"`
|
|
}
|
|
|
|
func loadConfig() {
|
|
configFile, err := os.Open("config.json")
|
|
if err != nil {
|
|
postLog.Fatal(fmt.Sprintf("Failed to open config file: %v, err: %v", configFile, err))
|
|
}
|
|
defer configFile.Close()
|
|
decoder := json.NewDecoder(configFile)
|
|
if err := decoder.Decode(&Config); err != nil {
|
|
postLog.Fatal(fmt.Sprintf("Failed to decode config file: %v, err: %v", configFile, err))
|
|
}
|
|
|
|
if Config.DebugMode {
|
|
isDebug = true
|
|
}
|
|
|
|
if Config.Debug.ListenAddr != "" {
|
|
DebugListenAddr = Config.Debug.ListenAddr
|
|
} else {
|
|
DebugListenAddr = "0.0.0.0"
|
|
}
|
|
if Config.Debug.ListenPort != 0 {
|
|
DebugListenPort = Config.Debug.ListenPort
|
|
} else {
|
|
DebugListenPort = 10080
|
|
}
|
|
}
|