英文:
Missing Field or Method
问题
var client := http.Client
由于某种原因,这段代码出现了错误消息“缺少变量或初始化”。有人可以告诉我为什么吗?我不明白我做错了什么。
英文:
var client := http.Client
For whatever reason this code is giving the error message missing variable or initialization. Can someone enlighten me on why? I'm not understanding what I have done wrong.
答案1
得分: 0
在Go语言中,我们使用:=
或var =
来初始化变量。在你的情况下,你可以将其重写为:
var client = http.Client{}
或者
client := http.Client{}
这两种方式都会触发变量的类型推断。你也可以使用var
和类型来显式声明一个类型。在你的情况下,如果你想要强制指定类型,你可以这样写:
var client http.Client = http.Client{}
英文:
In Go we use :=
or var =
for initializing variables. In your case you can re-write it to be:
var client = http.Client{}
or
client := http.Client{}
Either of these will trigger type inference of the variable. You can use var
with a type to explicitly declare a type as well. In your case if you wanted to enforce the type you could write:
var client http.Client = http.Client{}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论