This repository is archived and the code was moved here: https://github.com/jfenske89/gobasrv
A base Go service implementation, with graceful shutdown handling.
Once your service has been initialized, execute your logic using the Run
or RunWithContext
function.
// Run executes the main service logic
Run(logic func(context.Context) error) error
// RunWithContext executes the main service logic with a parent context
RunWithContext(context.Context, logic func(context.Context) error) error
Define graceful shutdown routines using the RegisterShutdownHandler
function.
// Shutdown executes shutdown functions and exits
RegisterShutdownHandler(logic func(context.Context) error)
These functions are executed in parallel before the application exits.
The context passed to these handlers has a 30 second deadline. So execution cannot exceed that time.
See ./examples/basic/main.go for a basic example.