logger/at_exit.go
2024-08-09 14:25:34 -06:00

29 lines
505 B
Go

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()
}
}