我把所有的服务器问题都作为一个[]数组来处理。问题是如何切片(GroupBy)状态,可引导。我只想把状态=可用,可引导=假
控制器
slicedBy := make(map[string]interface{})
server := blockstorage.ListVolumes(tenantID.(string)) <----- this is array
for _, sg := range server{
slicedBy[sg.ID] = sg.Status <------- slice by Status
slicedBy[sg.ID] = sg.Bootable <------- slice by Bootable
}Json阵列
{
id 123
status available
bootable false
...
}服务器作为数组
[
{
"id": "a8b123fc-a141-4682-b65b-d56899621959",
"status": "available",
"size": 1,
"availability_zone": "nova",
"attachments": [],
"name": "snapshot 1",
"description": "",
"bootable": "false",
},
{
"id": "ccb734d4-c098-4929-8ce5-281b6a58421d",
"status": "error",
"size": 2,
"availability_zone": "nova",
"attachments": [],
"name": "",
"description": "",
"volume_type": "",
"bootable": "false",
"volume_image_metadata": {
"signature_verified": "False"
}
},发布于 2019-04-01 06:42:55
for _, sg := range server {
if(sg.Status == "available" && sg.Bootable == "false"){
jsons["Data"] = sg
}
}效果很好。我刚找到它。
https://stackoverflow.com/questions/55447860
复制相似问题