You can avoid this by using :
if err := DoFoo(); err != nil { ...
The 'err' variable will be local to the 'if' so you can write also : if err := DoBar(); err != nil { ...
It is also nice to write it in one line :-)