I don't really understand how this code works, specifically e.(Exit)
, could someone explain?
type Exit struct{ Code int }
func handleExit() {
if e := recover(); e != nil {
if exit, ok := e.(Exit); ok == true {
os.Exit(exit.Code)
}
panic(e)
}
}
func main() {
defer handleExit()
panic(Exit{1})
}