feat(config): add debug server configuration options
- 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
This commit is contained in:
@@ -2,6 +2,7 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Watchdog_Linux-systemd/monitor"
|
"Watchdog_Linux-systemd/monitor"
|
||||||
|
"Watchdog_Linux-systemd/postLog"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"os"
|
"os"
|
||||||
@@ -44,6 +45,7 @@ func ExecuteCommand(input string) error {
|
|||||||
switch cmdType {
|
switch cmdType {
|
||||||
case "monitor.add":
|
case "monitor.add":
|
||||||
serviceName := getContent(input, "serviceName")
|
serviceName := getContent(input, "serviceName")
|
||||||
|
postLog.Info(fmt.Sprintf("Add service monitor: %s", serviceName))
|
||||||
if len(serviceName) != 0 {
|
if len(serviceName) != 0 {
|
||||||
err := monitor.AddServiceMonitor(serviceName)
|
err := monitor.AddServiceMonitor(serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -52,6 +54,7 @@ func ExecuteCommand(input string) error {
|
|||||||
}
|
}
|
||||||
case "monitor.remove":
|
case "monitor.remove":
|
||||||
serviceName := getContent(input, "serviceName")
|
serviceName := getContent(input, "serviceName")
|
||||||
|
postLog.Info(fmt.Sprintf("Remove service monitor: %s", serviceName))
|
||||||
if len(serviceName) != 0 {
|
if len(serviceName) != 0 {
|
||||||
err := monitor.RemoveServiceMonitor(serviceName)
|
err := monitor.RemoveServiceMonitor(serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
15
config.go
15
config.go
@@ -10,6 +10,10 @@ import (
|
|||||||
|
|
||||||
var Config struct {
|
var Config struct {
|
||||||
DebugMode bool `json:"debugMode"`
|
DebugMode bool `json:"debugMode"`
|
||||||
|
Debug struct {
|
||||||
|
ListenAddr string `json:"listenAddr"`
|
||||||
|
ListenPort int `json:"listenPort"`
|
||||||
|
} `json:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() {
|
func loadConfig() {
|
||||||
@@ -26,4 +30,15 @@ func loadConfig() {
|
|||||||
if Config.DebugMode {
|
if Config.DebugMode {
|
||||||
isDebug = true
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"debugMode": true
|
"debugMode": true,
|
||||||
|
"debug": {
|
||||||
|
"listenAddr": "0.0.0.0",
|
||||||
|
"listenPort": 10080
|
||||||
|
}
|
||||||
}
|
}
|
||||||
7
main.go
7
main.go
@@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var (
|
||||||
listenAddr = "127.0.0.1"
|
listenAddr = "127.0.0.1"
|
||||||
listenPort = 10080
|
listenPort = 10080
|
||||||
Type = "tcp"
|
Type = "tcp"
|
||||||
@@ -32,10 +32,15 @@ var softwareInfo SoftwareInfo = SoftwareInfo{
|
|||||||
|
|
||||||
var isDebug bool
|
var isDebug bool
|
||||||
|
|
||||||
|
var DebugListenAddr string
|
||||||
|
var DebugListenPort int
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
loadConfig()
|
loadConfig()
|
||||||
if isDebug == true {
|
if isDebug == true {
|
||||||
postLog.SetDebugMode(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))
|
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user