sigint

package module
v0.0.0-...-7e8d2ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2015 License: MIT Imports: 3 Imported by: 8

README

sigint

CTRL+C handler for my command line Go apps. Example:

import (
	"log"
	"os"

	"github.com/adampresley/sigint"
)

sigint.ListenForSIGINT(func() {
	log.Println("Shutting down...")
	os.Exit(0)
})

Visit http://godoc.org/github.com/adampresley/sigint for documentation.

License

The MIT License (MIT)

Copyright (c) 2014 Adam Presley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL