Variable not declared, inside a if..else statement

前端 未结 2 1652
情歌与酒
情歌与酒 2021-01-04 00:53

I\'m just started learning go lang, and I am confused about declaring variables in go lang

for example I\'ve declare req, er inside if...el

2条回答
  •  悲&欢浪女
    2021-01-04 01:44

    This is because you have declared the variables req and er inside the if else condition and are trying to use it outside the scope (the scope is just the if and else inside which they are declared).

    You need to declare er and req outside the if else

提交回复
热议问题