Actually, that wasn't really the point of my paste. But since you ask: Nearly. You can do this:
if value, err := bar(); err != nil {
return err
}
Note that this syntax declares "value" in the "if" scope. You can only access it inside the "then" block or in an "else" block:
if value, err := bar(); err != nil {
return err
} else {
log.Print(value) // this compiles
}
log.Print(value) // does not compile
So if you need it later, you have to do:
var value MyType
var err error
if value, err = bar(); err != nil {
return err
}
Note that you cannot do this:
var value MyType
if value, err := bar(); err != nil {
return err
}
This would, again, declare a new "value" that shadows the outer "value" inside the "if" scope. (Go would fail to compile it since it doesn't allow unused variables.)