You can create a zero-valued error (which will be nil) by declaring the variable.
var err error
if xxx {
err = funcA()
} else {
err = funcB()
}
It’s a common idiom, and you’ll see it in plenty of code.
You can create a zero-valued error (which will be nil) by declaring the variable.
var err error
if xxx {
err = funcA()
} else {
err = funcB()
}
It’s a common idiom, and you’ll see it in plenty of code.