signals

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: MIT Imports: 3 Imported by: 0

README

🚨 Signals

codecov Test Action Status

Signals is a simple package to intercept Interrupt signals.

⚙️ Installation

go get -u czechia.dev/signals

👀 Example

package main

import (
	"fmt"
	"net/http"

	"czechia.dev/signals"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Hello, World! 👋")
}

func main() {
	fmt.Println("starting application")
	go http.ListenAndServe(":8080", http.HandlerFunc(handler))

	signals.Interrupt(func() error {
		fmt.Println("interrupt signal received")
		return nil
	})
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Signals chan os.Signal

Signals is a channel that intercepts Interrupt signals.

The channel is global and public so that other packages may send Interrupt signals to initiate the stopFunc.

Functions

func Interrupt

func Interrupt(stopFunc func() error) error

Interrupt takes a stopFunc and executes it whenever the app receives an Interrupt signal.

The stopFunc is typically configured to initiate a clean shutdown of the application.

This function can be the last statement in func main() where the return parameters are discarded, but it can also be the last statement in a CLI action where the returned error is used to determine the exit code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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