Skip to content

dwburke/atexit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

atexit

Quick and dirty docs, will fill out later...

My primary use case is for embedded services, and loggers... it's tedious to make sure everything properly exits / closes files, etc... with atexit you can "register" a function to run at program exit in other packages.

It's not perfect, but it's "good enough" for me, hopefully it's good enough for you.

Pull requests welcome.

cmd/root.go

import "github.com/dwburke/atexit"

func init() {
    cobra.OnInitialize(initConfig)
    cobra.OnInitialize(natsqueue.Run)

    // there's other things going on there
    ...

}

main.go

func main() {
    defer atexit.AtExit()
    cmd.Execute()
}

natsqueue/server.go

func Execute() {
    // initializer code here
    ...

    atexit.Add(Shutdown)
}

func Shutdown() {
    // do shutdown things
    ...
}

About

Go package to run things when program ends

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages