Files
nomad/jobspec/utils.go
hashicorp-copywrite[bot] 4f55df8306 Adding explicit MPL license for sub-package (#18219)
This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-16 09:59:07 -05:00

38 lines
811 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package jobspec
// flattenMapSlice flattens any occurrences of []map[string]interface{} into
// map[string]interface{}.
func flattenMapSlice(m map[string]interface{}) map[string]interface{} {
newM := make(map[string]interface{}, len(m))
for k, v := range m {
var newV interface{}
switch mapV := v.(type) {
case []map[string]interface{}:
// Recurse into each map and flatten values
newMap := map[string]interface{}{}
for _, innerM := range mapV {
for innerK, innerV := range flattenMapSlice(innerM) {
newMap[innerK] = innerV
}
}
newV = newMap
case map[string]interface{}:
// Recursively flatten maps
newV = flattenMapSlice(mapV)
default:
newV = v
}
newM[k] = newV
}
return newM
}