我正在尝试使用Avi Go SDK来获取 gslb 配置。首先如下所示初始化与控制器的连接,aviClient, err := clients.NewAviClient("mycontroller", "USER", session.SetPassword("PASSS"), session.SetTenant("TENANT"), session.SetInsecure)if err != nil { t.Error(err)}然后尝试如下获取 gslb 详细信息,//Fetch gslbvar obj interface{}err = aviClient.AviSession.GetObjectByName("gslbservice", "mygslbname", &obj)fmt.Printf("%v\n", obj)并打印如下详细信息,map[_last_modified:1650419741251661 controller_health_status_enabled:true created_by:null description:null domain_names:[xxxxxxxxxxxxx] down_response:map[type:GSLB_SERVICE_DOWN_RESPONSE_ALL_RECORDS] enabled:true groups:[map[algorithm:GSLB_ALGORITHM_ROUND_ROBIN members:[map[cluster_uuid:xxxxxxxxxxxxxxxxxxxx enabled:true fqdn:xxxxxxxxxxxxxxxxxxxxxxxxx ip:map[addr:xxxxxxxxxxxxxxx type:V4] location:map[source:GSLB_LOCATION_SRC_INHERIT_FROM_SITE] ratio:1]] name:xxxxxxxxxxxxxxxxxxxxxxx priority:10]] health_monitor_refs:[https://xxxxxxxxxxxxxxxx] health_monitor_scope:GSLB_SERVICE_HEALTH_MONITOR_ALL_MEMBERS name:xxxxxxxxxxxxxxxx num_dns_ip:1 tenant_ref:https://xxxxxxxxxxxxxxxxxxx ttl:30 url:https://xxxxxxxxxxxxxxxxxxxx use_edns_client_subnet:true uuid:xxxxxxxxxxxxxxxxxxx wildcard_match:false]现在我想将整个映射存储到变量中,以便我可以如下进行断言和测试,var obj1 interface{} appDeployment := aviClient.AviSession.GetObjectByName("gslbservice", "mygslbname", &obj1)if err != nil { t.Error(err)}assert.Equal(t, appDeployment.domain_names, "mygslbname")我得到以下错误,appDeployment.domain_names undefined (type error has no field or method domain_names)任何协助?或者如何打印地图中的任何值,例如如何打印上面地图中的 ttl 值?
2 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
你有两个问题:
GetObjectByName
回报error
。所以,你appDeployment
实际上是一个错误您必须通过字符串键访问地图。因此,即使
appDeployment
是有效地图,您也必须domain_names
通过字符串键访问。
这应该解决两个问题:
var obj1 map[string]interface{}
err = aviClient.AviSession.GetObjectByName("gslbservice", "mygslbname", &obj1)
if err != nil {
t.Error(err)
}
assert.Equal(t, obj1["domain_names"], "mygslbname")
- 2 回答
- 0 关注
- 93 浏览
添加回答
举报
0/150
提交
取消