diff options
| author | Fuwn <[email protected]> | 2026-01-20 17:30:15 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 17:30:15 -0800 |
| commit | 8b0f24948b3bfb68bf0eb284a5a984f55c9693d4 (patch) | |
| tree | 23d60be9cb58f41f2c3c1f794567617818576328 /cmd | |
| parent | feat: Add dockerx command for multi-platform builds (diff) | |
| download | kaze-8b0f24948b3bfb68bf0eb284a5a984f55c9693d4.tar.xz kaze-8b0f24948b3bfb68bf0eb284a5a984f55c9693d4.zip | |
feat: Add POST /api/reload endpoint for config reload
- Add /api/reload endpoint that triggers configuration reload
- Always requires API key authentication (even if api.access is public)
- Returns error if no API keys are configured
- Update config.example.yaml with new endpoint and {group}/{name} format docs
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/kaze/main.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/cmd/kaze/main.go b/cmd/kaze/main.go index a71c03e..f4f61ac 100644 --- a/cmd/kaze/main.go +++ b/cmd/kaze/main.go @@ -131,20 +131,21 @@ func main() { logger.Info("kaze is running", "address", fmt.Sprintf("http://%s:%d", cfg.Server.Host, cfg.Server.Port)) - // Reload function - reloadConfig := func() { + // Reload function (returns error for API endpoint) + var reloadConfig func() error + reloadConfig = func() error { logger.Info("reloading configuration...") newCfg, err := config.Load(*configPath) if err != nil { logger.Error("failed to reload configuration", "error", err) - return + return fmt.Errorf("failed to load configuration: %w", err) } // Validate the new configuration if len(newCfg.Groups) == 0 { logger.Error("invalid configuration: no monitor groups defined") - return + return fmt.Errorf("invalid configuration: no monitor groups defined") } // Stop current scheduler @@ -160,7 +161,7 @@ func main() { logger.Error("failed to create new scheduler", "error", err) // Restart old scheduler sched.Start() - return + return fmt.Errorf("failed to create new scheduler: %w", err) } // Replace scheduler @@ -184,11 +185,12 @@ func main() { logger.Error("server error", "error", err) } }() - return + return fmt.Errorf("failed to create new server: %w", err) } - // Replace server + // Replace server and set reload func on new server srv = newSrv + srv.SetReloadFunc(reloadConfig) // Start new server go func() { @@ -201,8 +203,13 @@ func main() { logger.Info("configuration reloaded successfully", "groups", len(cfg.Groups), "incidents", len(cfg.Incidents)) + + return nil } + // Set reload function on server for API endpoint + srv.SetReloadFunc(reloadConfig) + // Wait for shutdown signal or config changes for { select { |