atexit

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 4 Imported by: 103

README

About

Build Status

Simple atexit implementation for Go.

Note that you have to call atexit.Exit and not os.Exit to terminate your program (that is, if you want the atexit handlers to execute).

Example usage

package main

import (
    "fmt"

    "github.com/tebeka/atexit"
)

func handler() {
    fmt.Println("Exiting")
}

func main() {
	atexit.Register(handler)
	atexit.Exit(0)
}

Install

go get github.com/tebeka/atexit

Contact

Documentation

Overview

Package atexit lets you define handlers when the program exits.

Add handlers using Register. You must call atexit.Exit to get the handler invoked (and then terminate the program).

This package also provides replacements to log.Fatal, log.Fatalf and log.Fatalln.

Example:

package main

import (
    "fmt"

    "github.com/tebeka/atexit"
)

func handler() {
    fmt.Println("Exiting")
}

func main() {
        atexit.Register(handler)
        atexit.Exit(0)
}

Index

Constants

View Source
const (
	// Version is package version
	Version = "0.3.0"
)

Variables

This section is empty.

Functions

func Exit

func Exit(code int)

Exit runs all the atexit handlers and then terminates the program using os.Exit(code)

func Fatal

func Fatal(v ...interface{})

Fatal runs all the atexit handler then calls log.Fatal (which will terminate the program)

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf runs all the atexit handler then calls log.Fatalf (which will terminate the program)

func Fatalln

func Fatalln(v ...interface{})

Fatalln runs all the atexit handler then calls log.Fatalln (which will terminate the program)

Types

type HandlerID added in v0.3.0

type HandlerID uint

func Register

func Register(handler func()) HandlerID

Register adds a handler, call atexit.Exit to invoke all handlers.

func (HandlerID) Cancel added in v0.3.0

func (id HandlerID) Cancel() error

Cancel cancels the handler associated with id

Jump to

Keyboard shortcuts

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