fix: address code review — HTTP client timeout, errors.Join, remove unused OnReload
- WaitForHealth: use http.Client with 2s timeout instead of DefaultClient - Daemon.Stop: use errors.Join for proper error unwrapping - Remove unused OnReload field from DaemonOptions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0696d32042
commit
953a95f26f
2 changed files with 4 additions and 6 deletions
|
|
@ -26,10 +26,6 @@ type DaemonOptions struct {
|
|||
|
||||
// HealthChecks are additional health check functions.
|
||||
HealthChecks []HealthCheck
|
||||
|
||||
// OnReload is called when SIGHUP is received.
|
||||
// Use for config reloading. Leave nil to ignore SIGHUP.
|
||||
OnReload func() error
|
||||
}
|
||||
|
||||
// Daemon manages daemon lifecycle: PID file, health server, graceful shutdown.
|
||||
|
|
@ -135,7 +131,7 @@ func (d *Daemon) Stop() error {
|
|||
d.running = false
|
||||
|
||||
if len(errs) > 0 {
|
||||
return fmt.Errorf("shutdown errors: %v", errs)
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,10 @@ func WaitForHealth(addr string, timeoutMs int) bool {
|
|||
deadline := time.Now().Add(time.Duration(timeoutMs) * time.Millisecond)
|
||||
url := fmt.Sprintf("http://%s/health", addr)
|
||||
|
||||
client := &http.Client{Timeout: 2 * time.Second}
|
||||
|
||||
for time.Now().Before(deadline) {
|
||||
resp, err := http.Get(url)
|
||||
resp, err := client.Get(url)
|
||||
if err == nil {
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue