为了账号安全,请及时绑定邮箱和手机立即绑定

如何访问此 Go 结构?

如何访问此 Go 结构?

Go
翻过高山走不出你 2022-08-30 15:21:03
我试图理解这个Go结构:type ListClustersOutput struct {    _ struct{} `type:"structure"`    // A list of all of the clusters for your account in the specified Region.    Clusters []*string `locationName:"clusters" type:"list"`    // The nextToken value to include in a future ListClusters request. When the    // results of a ListClusters request exceed maxResults, you can use this value    // to retrieve the next page of results. This value is null when there are no    // more results to return.    NextToken *string `locationName:"nextToken" type:"string"`}查看文档:https://golangdocs.com/structs-in-golang#defining-a-struct-in-go它给出了一个例子:type Fruit struct {    name string}这似乎非常不同。在更复杂的代码中,我认为这等同于但努力解压缩它。Clusters []*string `locationName:"clusters" type:"list"`name string我正在努力找出很多东西 - 大多数例子似乎都是指切片。他们为什么使用?type: "list"list什么是 ?locationName如何访问该结构中列表的第一个元素?请注意,对于最后一个问题,如果我使用(where is of this struct类型),我会得到一个指针。例如:result.Clusters[0]result    fmt.Println("Result: ", result.Clusters[0])    Result:  0xc000372260如何取消引用它?
查看完整描述

2 回答

?
跃然一笑

TA贡献1826条经验 获得超6个赞

您正在与结构标记作斗争。在代码中:

Clusters []*string `locationName:"clusters" type:"list"`

“聚类”字段的类型为 (),声明的其余部分是 2 个结构标记,您应该使用结构标记获取标记的值。[]*string


查看完整回答
反对 回复 2022-08-30
?
芜湖不芜

TA贡献1796条经验 获得超7个赞

以下是访问它的方法:

fmt.Println("Result: ", *result.Clusters[0])


查看完整回答
反对 回复 2022-08-30
  • 2 回答
  • 0 关注
  • 123 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号