gpt4 book ai didi

amazon-web-services - route53 列表托管区域输出抛出 "does not support indexing"错误

转载 作者:数据小太阳 更新时间:2023-10-29 03:21:55 24 4
gpt4 key购买 nike

我无法解析以下响应的输出。

当我包含该行时:

"fmt.Println(*r["HostedZones"][0])"

它抛出:

"type *route53.ListHostedZonesOutput does not support indexing". 

我想在输出中检索每个区域的“Id”和“Name”。如果类型不支持索引,我如何检索我需要的输出部分?

谢谢。

package main

import (
"log"
"fmt"
"reflect"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)

func main() {
r53 := route53.New(session.New())
r, err := r53.ListHostedZones(&route53.ListHostedZonesInput{})
if err != nil {
log.Fatal(err)
}
log.Println(r)
fmt.Println(reflect.TypeOf(r))
fmt.Println(*r["HostedZones"][0])
}

示例输出:

{
HostedZones: [{
CallerReference: "5E95CADD-59E-A6",
Config: {
PrivateZone: false
},
Id: "/hostedzone/Z1Q1TZTO",
Name: "testzone.local.",
ResourceRecordSetCount: 4
},{
CallerReference: "39895A3C-9B8B-95C2A3",
Config: {
PrivateZone: false
},
Id: "/hostedzone/Z2MXJQ7",
Name: "2.168.192.in-addr.arpa.",
ResourceRecordSetCount: 3
}],
IsTruncated: false,
MaxItems: "100"
}

最佳答案

这是一个如何获取 Id 的例子:

fmt.Println(*r.HostedZones[0].Id)

姓名:

fmt.Println(*r.HostedZones[0].Name)

关于amazon-web-services - route53 列表托管区域输出抛出 "does not support indexing"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52470994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com