go语言 declared and not used

go语言报错:
xxx declared and not used
代码类似:

1
2
3
4
5
6
7
8
9
10
11
12
var test Test
type Test struct{
    Name string
}

func main(){
    test := Text{name:"test"}
}

func set(t Test){
    test = t
}

经过排查发现,错误原因在于main函数里使用了 :=
应该是:
test = Text{name:”test”}

发表评论

电子邮件地址不会被公开。 必填项已用*标注