当前位置: 代码迷 >> 综合 >> go语言 declared and not used
  详细解决方案

go语言 declared and not used

热度:32   发布时间:2024-02-28 08:05:53.0

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

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”}