Documentation ¶
Overview ¶
run is a tiny module which makes spinning up and tearing down for a server program written in Go be more easier. See an example below for how to use.
Example ¶
package main import ( "context" "github.com/110y/run" ) func main() { run.Run(func(ctx context.Context) int { // Spin up your server here. // This blocks until one of termination signals (unix.SIGHUP, unix.SIGINT, unix.SIGTERM or unix.SIGQUIT) will be passed. <-ctx.Done() // Tear down your server here. // After this function has finished, run.Run exits the process with returned value of this function as its exit code. return 0 }) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run runs given f with a context created by context.Background and signal.NotifyContext. After f has finished, then Run exits the process by calling os.Exit with returned value of f as its exit code.
By default, signals will be passed to the signal.NotifyContext are unix.SIGHUP, unix.SIGINT, unix.SIGTERM and unix.SIGQUIT. You can change which signals will Run wait for by passing an Option created by WithSignals.
Types ¶
Click to show internal directories.
Click to hide internal directories.