gracefulexit

package module
v0.0.0-...-9eea9c7 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

graceful-exit

Graceful exit by capturing program exit signals.Suitable for k8s pod logout、docker container stop、program exit and etc.

Installation

Run the following command under your project:

go get -u github.com/NICEXAI/graceful-exit

Example
package main

import (
	"fmt"
	gracefulExit "github.com/NICEXAI/graceful-exit"
)

func main() {
	// main process
	fmt.Println("Process Running...")

	graceful := gracefulExit.NewGracefulExit()

	graceful.RegistryHandle("exit", func() {
		// the specific logic of graceful exit
		fmt.Println("Process Stop...")
	})

	graceful.Capture()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GracefulExist

type GracefulExist struct {
	// contains filtered or unexported fields
}

func NewGracefulExit

func NewGracefulExit() *GracefulExist

NewGracefulExit init new instance

func (*GracefulExist) Capture

func (r *GracefulExist) Capture()

Capture capture program exit signal Suitable for k8s pod logout、docker container stop、program exit and etc.

func (*GracefulExist) DestroyHandle

func (r *GracefulExist) DestroyHandle(name string)

DestroyHandle destroy handle after destroy, the handle will no longer be executed when the program exits

func (*GracefulExist) RegistryHandle

func (r *GracefulExist) RegistryHandle(name string, handler Handler)

RegistryHandle register handle the handle will be automatically executed when the program exits

type Handler

type Handler func()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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