xmtop/devices/devices.go

27 lines
785 B
Go
Raw Normal View History

2020-02-26 04:04:55 +08:00
package devices
2020-02-28 06:13:23 +08:00
import "log"
2020-02-26 04:04:55 +08:00
2020-02-28 06:13:23 +08:00
var shutdownFuncs []func() error
// RegisterShutdown stores a function to be called by gotop on exit, allowing
// extensions to properly release resources. Extensions should register a
// shutdown function IFF the extension is using resources that need to be
// released. The returned error will be logged, but no other action will be
// taken.
func RegisterShutdown(f func() error) {
shutdownFuncs = append(shutdownFuncs, f)
}
// Shutdown will be called by the `main()` function if gotop is exited
// cleanly. It will call all of the registered shutdown functions of devices,
// logging all errors but otherwise not responding to them.
2020-02-26 04:04:55 +08:00
func Shutdown() {
for _, f := range shutdownFuncs {
2020-02-28 06:13:23 +08:00
err := f()
if err != nil {
log.Print(err)
}
2020-02-26 04:04:55 +08:00
}
}