signals

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 3 Imported by: 9

README

gone signals

Run a signal handler and call functions based on a signal->function map.

Each signal will be notified on it's own 1-buffered channel, so no signal will be lost unless there's an equal signal pending.

Example

import (
	"github.com/One-com/gone/signals"
    "os"
	"syscall"
)

// ... define your functions

func init() {

    handledSignals := signals.Mappings{
        syscall.SIGINT  : onSignalExit,
		syscall.SIGTERM : onSignalExitGraceful,
		syscall.SIGHUP  : onSignalReload,
		syscall.SIGUSR2 : onSignalRespawn,
		syscall.SIGTTIN : onSignalIncLogLevel,
		syscall.SIGTTOU : onSignalDecLogLevel,
	}

	signals.RunSignalHandler(handledSignals)
}

Documentation

Overview

Package signals provides a generic signal handler which will call simple functions based on a mapping from signal to function.

The signal handler will select over a set of signal channels being buffered by 1 signal. This means that a signal will only be lost of there's another similar signal pending.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunSignalHandler

func RunSignalHandler(m Mappings)

RunSignalHandler spawns a go-routine which will call the provided Actions when receiving the corresponding signals.

Types

type Action

type Action func()

Action is a function called when an OS signal is received.

type Mappings

type Mappings map[os.Signal]Action

Mappings map OS signals to functions

Jump to

Keyboard shortcuts

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