v1.15.2
v1.15.2
This commit is contained in:
@@ -711,7 +711,7 @@ func TestGetListCloudbroker(t *testing.T) {
|
||||
getResult("Node list", bytes, node_cb.ListNodes{}, t)
|
||||
// Get
|
||||
listNode, _ := client.CloudBroker().Node().List(context.Background(), node_cb.ListRequest{})
|
||||
if len(listLB.Data) > 0 {
|
||||
if listNode != nil && len(listNode.Data) > 0 {
|
||||
id := listNode.Data[0].ID
|
||||
bytes, err = client.CloudBroker().Node().GetRaw(context.Background(), node_cb.GetRequest{NID: id})
|
||||
if err != nil {
|
||||
@@ -725,11 +725,11 @@ func TestGetListCloudbroker(t *testing.T) {
|
||||
}
|
||||
getResult("Node get_network_info", bytes, node_cb.RecordNodeNetworkInfo{}, t)
|
||||
} else {
|
||||
t.Errorf("Can not test Node get because LB list is empty")
|
||||
t.Errorf("Can not test Node get because node list is empty")
|
||||
}
|
||||
|
||||
// Node GetPCIDevices
|
||||
if len(listNode.Data) > 0 {
|
||||
if listNode != nil && len(listNode.Data) > 0 {
|
||||
id := listNode.Data[0].ID
|
||||
bytes, err = client.CloudBroker().Node().GetPCIDevicesRaw(context.Background(), node_cb.GetPCIDevicesRequest{NodeID: id})
|
||||
if err != nil {
|
||||
|
||||
@@ -183,6 +183,9 @@ func GetMapFromBytes(bytes []byte) (map[string]interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(unmarshalSlice) == 0 {
|
||||
return map[string]interface{}{}, nil
|
||||
}
|
||||
t, ok := unmarshalSlice[0].(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, err
|
||||
@@ -228,10 +231,20 @@ func getMapBytes(value map[string]interface{}) map[string]interface{} {
|
||||
func GetMapFromStructure(structure any) map[string]interface{} {
|
||||
typ := reflect.TypeOf(structure)
|
||||
|
||||
return getMapStruct(typ)
|
||||
for typ.Kind() == reflect.Slice || typ.Kind() == reflect.Ptr {
|
||||
typ = typ.Elem()
|
||||
}
|
||||
|
||||
return getMapStruct(typ, make(map[reflect.Type]bool))
|
||||
}
|
||||
|
||||
func getMapStruct(t reflect.Type) map[string]interface{} {
|
||||
func getMapStruct(t reflect.Type, visited map[reflect.Type]bool) map[string]interface{} {
|
||||
if visited[t] {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
visited[t] = true
|
||||
defer func() { visited[t] = false }()
|
||||
|
||||
temporary := make(map[string]interface{})
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
tag := t.Field(i).Tag.Get("json")
|
||||
@@ -243,16 +256,16 @@ func getMapStruct(t reflect.Type) map[string]interface{} {
|
||||
elem := t.Field(i).Type.Elem()
|
||||
switch elem.Kind() {
|
||||
case reflect.Struct:
|
||||
temporary[tag] = getMapStruct(elem)
|
||||
temporary[tag] = getMapStruct(elem, visited)
|
||||
default:
|
||||
temporary[tag] = map[string]interface{}{}
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
if tag == "" {
|
||||
return getMapStruct(t.Field(i).Type)
|
||||
return getMapStruct(t.Field(i).Type, visited)
|
||||
} else {
|
||||
temporary[tag] = getMapStruct(t.Field(i).Type)
|
||||
temporary[tag] = getMapStruct(t.Field(i).Type, visited)
|
||||
}
|
||||
// в этом месте работает некорректно для вложенных структур без json тегов (scope - все в cloudbroker)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user