gpt4 book ai didi

api - slice ,groupBy []数组

转载 作者:数据小太阳 更新时间:2023-10-29 03:09:03 27 4
gpt4 key购买 nike

我已经通过 [] 数组解决了所有服务器问题。问题是如何 slice (groupBy)状态,可启动。我只想接受 status = available, bootable = false

Controller

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
}
}

它工作得很好。我刚找到它。

关于api - slice ,groupBy []数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55447860/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com