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:
2026-04-28 20:48:54 +08:00
parent 8108d4d01f
commit 1432651a14
6 changed files with 93 additions and 61 deletions

View File

@@ -51,53 +51,49 @@ type Config struct {
Debug bool `json:"debug"`
Watchdog struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
Port int `json:"port"`
} `json:"watchdog"`
Notification struct {
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled"`
Method string `json:"method"`
} `json:"notification"`
Webhook struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Body map[string]string `json:"body"`
Method string `json:"method"`
URL string `json:"url"`
Headers string `json:"headers"`
Body string `json:"body"`
} `json:"webhook"`
}
var CurrentConfig = Config{
ListenAddr: "0.0.0.0",
ListenPort: "7000",
FrpcPath: "",
ListenAddr: "0.0.0.0",
ListenPort: "7000",
FrpcPath: "",
InstancePath: "",
Debug: false,
Watchdog: struct {
Watchdog: struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
Port int `json:"port"`
}{
Enabled: false,
Port: 0,
Port: 0,
},
Notification: struct {
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled"`
Method string `json:"method"`
}{
Enabled: false,
Method: "webhook",
},
Webhook: struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Body map[string]string `json:"body"`
Method string `json:"method"`
URL string `json:"url"`
Headers string `json:"headers"`
Body string `json:"body"`
}{
Method: "",
URL: "",
Headers: map[string]string{
"Content-Type": "",
},
Body: map[string]string{
"text": "",
},
Headers: "Content-Type: application/json",
Body: "",
},
}