refactor(socket): decouple command handling and add message sending

- Move command handler to variable for better flexibility
- Add SendMsg function for sending messages through socket
- Fix missing return statements in command execution
- Improve error handling in monitor exception reporting
This commit is contained in:
2026-04-28 19:55:45 +08:00
parent 3a0b591d5e
commit 58a8efc17a
4 changed files with 67 additions and 28 deletions

View File

@@ -50,7 +50,8 @@ func ExecuteCommand(input string) error {
err := monitor.AddServiceMonitor(serviceName)
if err != nil {
return fmt.Errorf("failed to add service monitor: %v", err)
}
}
return nil
}
case "monitor.remove":
serviceName := getContent(input, "serviceName")
@@ -60,9 +61,11 @@ func ExecuteCommand(input string) error {
if err != nil {
return fmt.Errorf("failed to remove service monitor: %v", err)
}
return nil
}
case "watchdog.shutdown":
os.Exit(0)
return nil
}
return fmt.Errorf("unknown command")
}