Why does golang compiler think the variable is declared but not used?

The err inside the for is shadowing the err outside the for, and it’s not being used (the one inside the for). This happens because you are using the short variable declaration (with the := operator) which declares a new err variable that shadows the one declared outside the for.

Leave a Comment