context

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package context provides utilities wrapping the native go/context package for catching and handling multiple interrupts.

The main use-case is to to attach an interrupt signal handler to the context. This can be used from your CLI applications to ensure a graceful shutdown of the scanning and to clean up any resources mid-flight

import "github.com/assetnote/kiterunner/pkg/context"

...

if err := scan.ScanDomainOrFile(context.Context(), domain, opts...); err != nil {
	log.Fatal().Err(err).Msg("failed to scan domain")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInterruptCancellation

func AddInterruptCancellation(ctx context.Context, cancel context.CancelFunc)

AddInterruptCancellation will add an interrupt handler that will catch the first SIGTERM and cancel the context upon second SIGTERM, the program will exit immediately This wrapping allows for graceful shutdown of the application

func Cancel

func Cancel()

Cancel will cancel the global context. Calling this multiple times is the equivalent of cancelling the same context multiple times

func Context

func Context() context.Context

Context will initialize the global context and attach the interrupt handler that will cancel the context upon SIGTERM. This is safe to call from multiple goroutines and will always return the same context

func InitContext

func InitContext()

InitContext will initialize the global context used to catch interrupts. This is automatically called by Context and Cancel

Types

This section is empty.

Jump to

Keyboard shortcuts

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