Documentation
¶
Overview ¶
Package app provides the core runtime lifecycle harness for services.
Index ¶
- type App
- func (a *App) Attach(name string, target any)
- func (a *App) AttachPeriodic(name string, interval time.Duration, fn func(context.Context) error)
- func (a *App) AttachRunner(name string, fn func(context.Context) error)
- func (a *App) DefaultRouter() *chi.Mux
- func (a *App) FatalIf(err error, msg string)
- func (a *App) Healthz(w http.ResponseWriter, r *http.Request)
- func (a *App) Logger() *slog.Logger
- func (a *App) Meter() metric.Meter
- func (a *App) Readyz(w http.ResponseWriter, r *http.Request)
- func (a *App) Run(ctx context.Context) error
- func (a *App) ServeHTTP(target any, handler http.Handler)
- func (a *App) ServeHTTPConfig(cfg httpx.Config, handler http.Handler)
- func (a *App) Telemetry() *telemetry.Telemetry
- type Config
- type Metered
- type Pinger
- type ProfilingConfig
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the central runtime coordinator for HTTP servers, background runners, and graceful shutdown.
func (*App) Attach ¶
Attach registers a component implementing Pinger, Metered, Runner, or io.Closer.
func (*App) AttachPeriodic ¶
AttachPeriodic runs fn periodically at the given interval until the application context is canceled.
func (*App) AttachRunner ¶
AttachRunner registers a named background runner.
func (*App) DefaultRouter ¶
DefaultRouter returns a Chi router preconfigured with observability middleware, recoverer, and system routes.
func (*App) Healthz ¶
func (a *App) Healthz(w http.ResponseWriter, r *http.Request)
Healthz handles liveness probes.
func (*App) Readyz ¶
func (a *App) Readyz(w http.ResponseWriter, r *http.Request)
Readyz handles readiness probes by checking all registered pingers.
func (*App) Run ¶
Run starts all servers and runners, blocking until ctx is canceled or an error occurs.
func (*App) ServeHTTP ¶
ServeHTTP registers an HTTP server to be managed by the application. target can be a port string (e.g. "8080", ":8080"), an httpx.Config, or an *httpx.Config.
func (*App) ServeHTTPConfig ¶
ServeHTTPConfig registers an HTTP server configured via httpx.Config.
type Config ¶
type Config struct {
ServiceName string `toml:"service_name" env:"SERVICE_NAME" env-default:"app"`
Environment string `toml:"environment" env:"APP_ENV" env-default:"local"`
ShutdownTimeout time.Duration `toml:"shutdown_timeout" env:"SHUTDOWN_TIMEOUT" env-default:"10s" comment:"Graceful shutdown timeout"`
Logger logger.Config `toml:"logger" env-prefix:"LOG_"`
Telemetry telemetry.Config `toml:"telemetry"`
Profiling ProfilingConfig `toml:"profiling"`
}
Config defines runtime application settings.
type ProfilingConfig ¶
type ProfilingConfig struct {
Enabled bool `toml:"enabled" env:"PPROF_ENABLED" env-default:"false" comment:"Enable /debug/pprof"`
BlockRate int `toml:"block_rate" env:"PPROF_BLOCK_RATE" env-default:"0" comment:"Block profiling rate (0: disabled, 1: all)"`
MutexFraction int `toml:"mutex_fraction" env:"PPROF_MUTEX_FRACTION" env-default:"0" comment:"Mutex profiling sample fraction (0: disabled)"`
}
ProfilingConfig defines pprof profiling settings.