Documentation
¶
Overview ¶
Package gootstrap provides small, composable helpers to bootstrap long-lived Go services.
A Runner returns two blocking lifecycle functions:
- start, which starts and blocks while the service is running.
- stop, which gracefully stops the service.
Use Run for the common case (start and stop on SIGINT/SIGTERM), or combine multiple runners with RunAll.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunUntilSignal ¶
RunUntilSignal starts a runner and waits for specified signals to stop it.
Types ¶
type Runner ¶
type Runner func() (start, stop func() error)
Runner defines a lifecycle factory that returns blocking start and stop functions for a long-lived process.
func RunAll ¶
RunAll accepts a list of runners and returns a new runner that starts all of them on start and stops all of them on stop.
Example ¶
worker := func(name string) Runner {
return func() (func() error, func() error) {
return func() error {
fmt.Println("start", name)
return nil
}, func() error {
fmt.Println("stop", name)
return nil
}
}
}
runner := RunAll(worker("http"), worker("metrics"))
start, stop := runner()
_ = start()
_ = stop()
func RunGracefulHttpServer ¶
RunGracefulHttpServer bootstraps an HTTP server with a graceful shutdown window that serves 503 responses for new requests before stopping.
func RunHTTPServer ¶
RunHTTPServer bootstraps a standard net/http server lifecycle.