feat: add dependency shutdown and configurable service endpoints

This commit is contained in:
2026-09-24 18:33:24 +08:00
parent 8a348951eb
commit f0991d3ff2
51 changed files with 1433 additions and 73 deletions

View File

@@ -41,12 +41,17 @@ func run(ctx context.Context, path string) (runErr error) {
}
// RunContext drains HTTP requests before returning. This scope owns dependencies
// and closes them exactly once, before closing the borrowed logger.
defer func() { runErr = errors.Join(runErr, deps.Close()) }()
defer func() {
runErr = errors.Join(runErr, deps.Close())
if cause := deps.Lifecycle.Err(); cause != nil && !errors.Is(runErr, cause) {
runErr = errors.Join(runErr, cause)
}
}()
app, err := handler.NewApp(deps)
if err != nil {
return err
}
defer func() { runErr = errors.Join(runErr, app.Close()) }()
logger.InfoContext(ctx, "service.starting", "address", app.Config().Address)
return app.RunContext(ctx)
return app.RunContext(deps.Lifecycle.Context())
}