diff --git a/command/commandParse.go b/command/commandParse.go index 211457b..06aacd4 100644 --- a/command/commandParse.go +++ b/command/commandParse.go @@ -2,6 +2,7 @@ package command import ( "Watchdog_Linux-systemd/monitor" + "Watchdog_Linux-systemd/postLog" "fmt" "strings" "os" @@ -44,6 +45,7 @@ func ExecuteCommand(input string) error { switch cmdType { case "monitor.add": serviceName := getContent(input, "serviceName") + postLog.Info(fmt.Sprintf("Add service monitor: %s", serviceName)) if len(serviceName) != 0 { err := monitor.AddServiceMonitor(serviceName) if err != nil { @@ -52,6 +54,7 @@ func ExecuteCommand(input string) error { } case "monitor.remove": serviceName := getContent(input, "serviceName") + postLog.Info(fmt.Sprintf("Remove service monitor: %s", serviceName)) if len(serviceName) != 0 { err := monitor.RemoveServiceMonitor(serviceName) if err != nil { diff --git a/config.go b/config.go index 921fbea..6eab2d8 100644 --- a/config.go +++ b/config.go @@ -10,6 +10,10 @@ import ( var Config struct { DebugMode bool `json:"debugMode"` + Debug struct { + ListenAddr string `json:"listenAddr"` + ListenPort int `json:"listenPort"` + } `json:"debug"` } func loadConfig() { @@ -26,4 +30,15 @@ func loadConfig() { 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 + } } diff --git a/config.json b/config.json index 1ecaa7d..47df6d2 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,7 @@ { - "debugMode": true + "debugMode": true, + "debug": { + "listenAddr": "0.0.0.0", + "listenPort": 10080 + } } \ No newline at end of file diff --git a/main.go b/main.go index 9a12237..40dea0a 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "fmt" ) -const ( +var ( listenAddr = "127.0.0.1" listenPort = 10080 Type = "tcp" @@ -32,10 +32,15 @@ var softwareInfo SoftwareInfo = SoftwareInfo{ var isDebug bool +var DebugListenAddr string +var DebugListenPort int + func main() { loadConfig() if isDebug == true { postLog.SetDebugMode(true) + listenAddr = DebugListenAddr + listenPort = DebugListenPort } postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer))