From de237c059ebf48ec09b9239b1cf4918646d82608 Mon Sep 17 00:00:00 2001 From: "s.maeda" Date: Sat, 27 Aug 2022 09:45:30 +0900 Subject: [PATCH] FindAllStats: Fix to get the json of resource when not an array --- service/stats.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/service/stats.go b/service/stats.go index f8e3b8f..17557e9 100644 --- a/service/stats.go +++ b/service/stats.go @@ -39,10 +39,17 @@ func (c *NitroClient) FindAllStats(resourceType string) ([]map[string]interface{ log.Printf("[WARN] nitro-go: FindStats No %s type found", resourceType) return nil, fmt.Errorf("[INFO] nitro-go: FindStats: No type of %s found", resourceType) } - resources := data[resourceType].([]interface{}) - ret := make([]map[string]interface{}, len(resources), len(resources)) - for i, v := range resources { - ret[i] = v.(map[string]interface{}) + ret := make([]map[string]interface{}, 0) + switch data[resourceType].(type) { + case []interface{}: + resources := data[resourceType].([]interface{}) + ret = make([]map[string]interface{}, len(resources), len(resources)) + for i, v := range resources { + ret[i] = v.(map[string]interface{}) + } + case map[string]interface{}: + resources := data[resourceType].(map[string]interface{}) + ret = append(ret, resources) } return ret, nil }