3 ms·
If it's a fairly big function, or a common way of dealing with errors in a package you can always define a func (nested or not): func foo() error { handl
by jawr 13y ago
If it's a fairly big function, or a common way of dealing with errors in a package you can always define a func (nested or not):
func foo() error {
handleErr = func(err error) bool {
if err != nil {
log.Println(err)
// do other stuff
return true
}
return false
}
err := bar()
if handleErr(err) { return err }
}
It's nice and concise.