logger/at_exit.go

29 lines
505 B
Go
Raw Normal View History

2024-08-09 20:25:34 +00:00
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()
}
}