Documentation
¶
Overview ¶
Package cli provides lightweight command dispatch and HTTP server lifecycle helpers for Ohm applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrHelp = errors.New("help requested")
ErrHelp requests command help.
var ErrUsage = errors.New("usage error")
ErrUsage reports command-line usage errors.
Functions ¶
func RunHTTPServer ¶
func RunHTTPServer(ctx context.Context, server *http.Server, shutdownTimeout time.Duration, hooks []ShutdownHook) error
RunHTTPServer runs server until it stops or ctx is canceled, then runs the shutdown hooks. The drain and the hooks share a single deadline derived from shutdownTimeout, so total shutdown stays bounded by that budget.
Types ¶
type Command ¶
type Command struct {
Name string
Summary string
Usage string
Run func(context.Context, IO, []string) error
}
Command is one application command.
func RoutesCommand ¶
RoutesCommand returns a command that prints registered routes.
func ServerCommand ¶
func ServerCommand(handler http.Handler, opts ...ServerOption) Command
ServerCommand returns a command that boots an HTTP server.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program dispatches application commands.
type ServerOption ¶
type ServerOption func(*serverConfig)
ServerOption configures ServerCommand.
func WithAddr ¶
func WithAddr(addr string) ServerOption
WithAddr configures the default server address.
func WithServerRunner ¶
func WithServerRunner(runner ServerRunner) ServerOption
WithServerRunner configures the server runner.
func WithShutdownHook ¶
func WithShutdownHook(hook ShutdownHook) ServerOption
WithShutdownHook registers a hook run during graceful shutdown. Hooks run in reverse registration order, sharing the single shutdown budget with the server drain so total shutdown stays bounded by the shutdown timeout.
func WithShutdownTimeout ¶
func WithShutdownTimeout(timeout time.Duration) ServerOption
WithShutdownTimeout configures graceful shutdown timeout.
type ServerRunner ¶
type ServerRunner func(ctx context.Context, server *http.Server, shutdownTimeout time.Duration, hooks []ShutdownHook) error
ServerRunner runs an HTTP server and, once it stops, runs the shutdown hooks within the shutdown budget. A runner owns the full lifecycle, so custom runners are responsible for invoking the hooks they are given.
type ShutdownHook ¶
ShutdownHook releases resources during graceful shutdown. Hooks run after the server stops serving, within the remaining shutdown budget, and are the seam for flushing telemetry such as OpenTelemetry providers before the process exits.