&Client{
url: u,
userAgent: conf.UserAgent,
httpClient: &http.Client{
Timeout: conf.Timeout,
Transport: tr,
},
credentials: conf.Credentials,
}
请问这冒号代表的是什么意思?
有疑问加站长微信联系(非本文作者)

&Client{
url: u,
userAgent: conf.UserAgent,
httpClient: &http.Client{
Timeout: conf.Timeout,
Transport: tr,
},
credentials: conf.Credentials,
}
请问这冒号代表的是什么意思?
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
`单行代码`
赋值,你可以理解为和
=
类似谢谢
申明变量并赋值
可以这么看,:是申明,=是赋值,所以:=就是申明并赋值
Composite literals, 根据已经声明的类型构造复合的变量,类似于 key: value, 应该不是声明变量
type Point3D struct { x, y, z float64 } type Line struct { p, q Point3D custom map[string]int }
l := &Line{ p: Point3D{}, q: Point3D{y: -4, z: 12.3}, custom: map[string]int{ "weight": 1, "color": 0, }, }
The key is interpreted as a field name for struct literals, an index for array and slice literals, and a key for map literals. For map literals, all elements must have a key. It is an error to specify multiple elements with the same field name or constant key value.
For struct literals the following rules apply:
A key must be a field name declared in the struct type. An element list that does not contain any keys must list an element for each struct field in the order in which the fields are declared. If any element has a key, every element must have a key. An element list that contains keys does not need to have an element for each struct field. Omitted fields get the zero value for that field. A literal may omit the element list; such a literal evaluates to the zero value for its type. It is an error to specify an element for a non-exported field of a struct belonging to a different package.
3Q!
3Q~
结构体/类的初始化方式,初始化类的时候给类的指定成员赋值。