Documentation ¶
Overview ¶
Package sigint provides a method to handle CTRL+C (SIGINT) in command line applications. This is useful for server style applications, like web and TCP servers.
This package is provided under the MIT license. Please see the LICENSE file for more information.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
func Listen(handler func())
Sets up a listener to execute a function when the SIGINT event or SIGTERM is fired (usually CTRL+C). The callback function has no arguments and does not need to return anything. This is a bit broader and works across more operating systems. The original function is kept for backward compatability.
func ListenForSIGINT ¶
func ListenForSIGINT(handler func())
Sets up a listener to execute a function when the SIGINT event is fired (usually CTRL+C). The callback function has no arguments and does not need to return anything.
Example ¶
This example sets up a SIGINT handler that simply exits the application.
package main import ( "log" "os" "github.com/adampresley/sigint" ) func main() { sigint.ListenForSIGINT(func() { log.Println("Shutting down...") os.Exit(0) }) }
Output:
Types ¶
This section is empty.