Skip to content

Commit

Permalink
Refactor to switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Wurm committed Jul 23, 2019
1 parent 493aa7c commit 8c508d1
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions libbeat/dashboards/modify_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,8 @@ func ReplaceIndexInIndexPattern(index string, content common.MapStr) common.MapS
return content
}

if objectMaps, ok := content["objects"].([]common.MapStr); ok {
// change index pattern name
for i, objectMap := range objectMaps {

objectMap["id"] = index
if attributes, ok := objectMap["attributes"].(common.MapStr); ok {
attributes["title"] = index
}
objectMaps[i] = objectMap
}
content["objects"] = objectMaps
} else if objects, ok := content["objects"].([]interface{}); ok {
switch objects := content["objects"].(type) {
case []interface{}:
// change index pattern name
for i, object := range objects {
objectMap, ok := object.(map[string]interface{})
Expand All @@ -72,6 +62,19 @@ func ReplaceIndexInIndexPattern(index string, content common.MapStr) common.MapS
objects[i] = objectMap
}
content["objects"] = objects
case []common.MapStr:
// change index pattern name
for i, objectMap := range objects {

objectMap["id"] = index
if attributes, ok := objectMap["attributes"].(common.MapStr); ok {
attributes["title"] = index
}
objects[i] = objectMap
}
content["objects"] = objects
default:
logp.Err("Unexpected object type %T, expected list of objects. Got: %#v", content["objects"], content["objects"])
}

return content
Expand Down

0 comments on commit 8c508d1

Please sign in to comment.