亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

golang 從地圖內部的地圖訪問值

golang 從地圖內部的地圖訪問值

Go
三國紛爭 2022-12-05 17:13:04
我正在利用Avi Go SDK來獲取 avi healthmonitor 配置,如下所示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]從地圖上,我能夠成功訪問名稱、monitor_port 等,它們位于地圖的根目錄中,如下所示assert.Equal(t, healthmonitormap["name"], "helloworldspringbootssl-dit1-monitor")assert.Equal(t, float64(443), healthmonitormap["monitor_port"])但是我無法理解如何訪問地圖內的地圖 http_request 和 http_response_code 之類的東西。任何幫助表示贊賞。
查看完整描述

1 回答

?
達令說

TA貢獻1821條經驗 獲得超6個贊

由于地圖的元素是 an ,interface{}因此您必須將其轉換為相應的類型才能將其作為地圖訪問,如下所示:


if value, ok := healthmonitormap["https_monitor"].(map[string]interface{}); ok {

    fmt.Println(value["http_request"]) //Output: GET /welcome HTTP/1.1 

}


查看完整回答
反對 回復 2022-12-05
  • 1 回答
  • 0 關注
  • 84 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號