我正在利用Avi Go SDK获取Avi健康监视器配置,如下所示
var healthmonitormap map[string]interface{}
err = aviClient.AviSession.GetObjectByName("healthmonitor", "healthmonitorname", &healthmonitormap)
if err != nil {
t.Error(err)
}
将运行状况监视器的元数据存储在healthmonitormap中,作为如下所示的映射
map[
_last_modified:1644392621383838
failed_checks:3
https_monitor:map[
http_request:GET /welcome HTTP/1.1
http_response_code:[HTTP_2XX HTTP_3XX]]
monitor_port:443
name:helloworldspringbootssl-dit1-monitor
receive_timeout:3
send_interval:10
successful_checks:3
tenant_ref:https://xxxxxxxxxxxxxxxx/api/tenant/tenant-xxxxxxxxxxxx
type:HEALTH_MONITOR_HTTPS
url:https://xxxxxxxxxxx/api/healthmonitor/healthmonitor-xxxxxxxxxxxxxxx
uuid:healthmonitor-xxxxxxxxxxxxxxxx]
从映射中,我能够成功访问name, monitor_port等。它们位于map的根目录
assert.Equal(t, healthmonitormap["name"], "helloworldspringbootssl-dit1-monitor")
assert.Equal(t, float64(443), healthmonitormap["monitor_port"])
然而,我不能够理解如何访问的东西,如http_request和http_response_code是映射内部的映射。
感谢您的帮助。
由于映射的元素是interface{}
,因此必须将其转换为相应的类型才能将其作为映射访问,如下所示:
if value, ok := healthmonitormap["https_monitor"].(map[string]interface{}); ok {
fmt.Println(value["http_request"]) //Output: GET /welcome HTTP/1.1
}