Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindAllStats: Fix to get the json of resource when not an array #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions service/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down