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

前端 未结 1 482
广开言路
广开言路 2020-12-03 22:07

I am a newbee to golang, and I write a program to test io package:

func main() {
    readers := []io.Reader{
         strings.NewReader(\"from string reader\         


        
相关标签:
1条回答
  • 2020-12-03 22:24

    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.

    0 讨论(0)
提交回复
热议问题