Hello,
I’m new in Go and I understand what the code does but would love an explanation about how to express what we do here and the logic behind why we do it like that.
And if so, my answer would be that the only difference is that after the first block of code, there is no err variable outside of the if’s scope, but in the second one, the err is defined outside of the if’s scope, so there’s still an err variable after the if’s closing } brace. One is not inherently better than the other; it depends on the other code around it.
Or maybe I misunderstood, in which case, could you rephrase your question?