MCPcopy Create free account
hub / github.com/compose-spec/compose-go / resolve

Function resolve

loader/normalize.go:218–256  ·  view source on GitHub ↗
(a any, fn func(s string) (string, bool), keepEmpty bool)

Source from the content-addressed store, hash-verified

216}
217
218func 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
259func setNameFromKey(dict map[string]any) {

Callers 1

NormalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…