fix(watchdog): fix watchdog unable to send webhook and simplify the parsing of json config
- Change webhook config headers and body from map to string format - Move command parsing logic to separate function in command.go - Add debug logging for webhook operations - Improve exception handling with proper JSON parsing - Simplify config loading logic with default values
This commit is contained in:
@@ -57,17 +57,29 @@ func LoadConfig(configPath string, getInitSystem func() string) error {
|
||||
return fmt.Errorf("failed to parse config file: %w", err)
|
||||
}
|
||||
|
||||
if fileConfig.ListenAddr != "" {
|
||||
global.CurrentConfig.ListenAddr = fileConfig.ListenAddr
|
||||
global.CurrentConfig.ListenAddr = fileConfig.ListenAddr
|
||||
global.CurrentConfig.ListenPort = fileConfig.ListenPort
|
||||
global.CurrentConfig.FrpcPath = fileConfig.FrpcPath
|
||||
global.CurrentConfig.InstancePath = fileConfig.InstancePath
|
||||
global.CurrentConfig.Debug = fileConfig.Debug
|
||||
global.CurrentConfig.Watchdog.Enabled = fileConfig.Watchdog.Enabled
|
||||
global.CurrentConfig.Watchdog.Port = fileConfig.Watchdog.Port
|
||||
global.CurrentConfig.Notification.Enabled = fileConfig.Notification.Enabled
|
||||
global.CurrentConfig.Notification.Method = fileConfig.Notification.Method
|
||||
global.CurrentConfig.Webhook.Method = fileConfig.Webhook.Method
|
||||
global.CurrentConfig.Webhook.URL = fileConfig.Webhook.URL
|
||||
global.CurrentConfig.Webhook.Headers = fileConfig.Webhook.Headers
|
||||
global.CurrentConfig.Webhook.Body = fileConfig.Webhook.Body
|
||||
|
||||
if fileConfig.ListenAddr == "" {
|
||||
global.CurrentConfig.ListenAddr = "0.0.0.0"
|
||||
}
|
||||
|
||||
if fileConfig.ListenPort != "" {
|
||||
global.CurrentConfig.ListenPort = fileConfig.ListenPort
|
||||
if fileConfig.ListenPort == "" {
|
||||
global.CurrentConfig.ListenPort = "7000"
|
||||
}
|
||||
|
||||
if fileConfig.FrpcPath != "" {
|
||||
global.CurrentConfig.FrpcPath = fileConfig.FrpcPath
|
||||
} else {
|
||||
if fileConfig.FrpcPath == "" {
|
||||
if getInitSystem() == "windows" {
|
||||
global.CurrentConfig.FrpcPath = "frp_client/frpc.exe"
|
||||
} else {
|
||||
@@ -75,22 +87,14 @@ func LoadConfig(configPath string, getInitSystem func() string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if fileConfig.InstancePath != "" {
|
||||
global.CurrentConfig.InstancePath = fileConfig.InstancePath
|
||||
} else {
|
||||
if fileConfig.InstancePath == "" {
|
||||
global.CurrentConfig.InstancePath = "./configs"
|
||||
}
|
||||
|
||||
global.CurrentConfig.Debug = fileConfig.Debug
|
||||
|
||||
if fileConfig.Watchdog.Port != 0 {
|
||||
global.CurrentConfig.Watchdog.Port = fileConfig.Watchdog.Port
|
||||
} else {
|
||||
if fileConfig.Watchdog.Port == 0 {
|
||||
global.CurrentConfig.Watchdog.Port = 12380
|
||||
}
|
||||
|
||||
global.CurrentConfig.Watchdog.Enabled = fileConfig.Watchdog.Enabled
|
||||
|
||||
if err := os.MkdirAll(global.CurrentConfig.InstancePath, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create config directory: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user