切片,groupBy []数组

slice, groupBy []array

作为 [] 数组,我遇到了所有服务器问题。问题是如何切片(groupBy)状态,可启动。我只想接受 status = available, bootable = false

控制器

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"
        }
    },
for _, sg := range server {
  if(sg.Status == "available" && sg.Bootable == "false"){
     jsons["Data"] = sg
  }
}

效果很好。我刚找到。