package logger import ( "github.com/sirupsen/logrus" "path/filepath" "runtime" ) var ( AtExit AtExitStruct ) type AtExitStruct struct { handlers []func() } func (aes *AtExitStruct) Register(newFunc func()) { _, file, _, _ := runtime.Caller(1) logrus.Tracef("At Exit Function Registered: %s", filepath.Base(file)) aes.handlers = append(aes.handlers, newFunc) } func (aes *AtExitStruct) Cleanup() { logrus.Info("Cleaning up resources") for _, handler := range aes.handlers { handler() } }