toMap converts a struct to a normalized map[string]interface{} via yaml round-trip. All nested maps are normalized to map[string]interface{}.
(v interface{})
| 82 | // toMap converts a struct to a normalized map[string]interface{} via yaml round-trip. |
| 83 | // All nested maps are normalized to map[string]interface{}. |
| 84 | func toMap(v interface{}) (map[string]interface{}, error) { |
| 85 | b, err := yaml.Marshal(v) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | var m map[string]interface{} |
| 90 | if err := yaml.Unmarshal(b, &m); err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | return normalizeMap(m), nil |
| 94 | } |
| 95 | |
| 96 | // normalizeMap recursively converts all map[interface{}]interface{} to map[string]interface{}. |
| 97 | func normalizeMap(m map[string]interface{}) map[string]interface{} { |
no test coverage detected