Add exit call

Former-commit-id: 4a89915826
This commit is contained in:
Owen
2025-11-03 14:15:16 -08:00
parent a7979259f3
commit 36fc3ea253
2 changed files with 46 additions and 0 deletions

View File

@@ -58,6 +58,10 @@ type Config struct {
}
func Run(ctx context.Context, config Config) {
// Create a cancellable context for internal shutdown control
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// Extract commonly used values from config for convenience
var (
endpoint = config.Endpoint
@@ -108,6 +112,14 @@ func Run(ctx context.Context, config Config) {
if err := apiServer.Start(); err != nil {
logger.Fatal("Failed to start HTTP server: %v", err)
}
// Listen for shutdown requests from the API
go func() {
<-apiServer.GetShutdownChannel()
logger.Info("Shutdown requested via API")
// Cancel the context to trigger graceful shutdown
cancel()
}()
}
// // Use a goroutine to handle connection requests