(a any, fn func(s string) (string, bool), keepEmpty bool)
| 216 | } |
| 217 | |
| 218 | func resolve(a any, fn func(s string) (string, bool), keepEmpty bool) (any, bool) { |
| 219 | switch v := a.(type) { |
| 220 | case []any: |
| 221 | var resolved []any |
| 222 | for _, val := range v { |
| 223 | if r, ok := resolve(val, fn, keepEmpty); ok { |
| 224 | resolved = append(resolved, r) |
| 225 | } |
| 226 | } |
| 227 | return resolved, true |
| 228 | case map[string]any: |
| 229 | resolved := map[string]any{} |
| 230 | for key, val := range v { |
| 231 | if val != nil { |
| 232 | resolved[key] = val |
| 233 | continue |
| 234 | } |
| 235 | if s, ok := fn(key); ok { |
| 236 | resolved[key] = s |
| 237 | } else if keepEmpty { |
| 238 | resolved[key] = nil |
| 239 | } |
| 240 | } |
| 241 | return resolved, true |
| 242 | case string: |
| 243 | if !strings.Contains(v, "=") { |
| 244 | if val, ok := fn(v); ok { |
| 245 | return fmt.Sprintf("%s=%s", v, val), true |
| 246 | } |
| 247 | if keepEmpty { |
| 248 | return v, true |
| 249 | } |
| 250 | return "", false |
| 251 | } |
| 252 | return v, true |
| 253 | default: |
| 254 | return v, false |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // Resources with no explicit name are actually named by their key in map |
| 259 | func setNameFromKey(dict map[string]any) { |
no outgoing calls
no test coverage detected
searching dependent graphs…