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

Function loadYamlFile

loader/loader.go:441–557  ·  view source on GitHub ↗
(ctx context.Context,
	file types.ConfigFile,
	opts *Options,
	workingDir string,
	environment types.Mapping,
	ct *cycleTracker,
	dict map[string]interface{},
	included []string,
)

Source from the content-addressed store, hash-verified

439}
440
441func loadYamlFile(ctx context.Context,
442 file types.ConfigFile,
443 opts *Options,
444 workingDir string,
445 environment types.Mapping,
446 ct *cycleTracker,
447 dict map[string]interface{},
448 included []string,
449) (map[string]interface{}, PostProcessor, error) {
450 ctx = context.WithValue(ctx, consts.ComposeFileKey{}, file.Filename)
451 if file.Content == nil && file.Config == nil {
452 content, err := os.ReadFile(file.Filename)
453 if err != nil {
454 return nil, nil, err
455 }
456 file.Content = content
457 }
458
459 processRawYaml := func(raw interface{}, processor PostProcessor) error {
460 converted, err := convertToStringKeysRecursive(raw, "")
461 if err != nil {
462 return err
463 }
464 cfg, ok := converted.(map[string]interface{})
465 if !ok {
466 return errors.New("top-level object must be a mapping")
467 }
468
469 if opts.Interpolate != nil && !opts.SkipInterpolation {
470 cfg, err = interp.Interpolate(cfg, *opts.Interpolate)
471 if err != nil {
472 return err
473 }
474 }
475
476 fixEmptyNotNull(cfg)
477
478 // Process includes first so that extended services have all merged attributes
479 if !opts.SkipInclude {
480 included = append(included, file.Filename)
481 err = ApplyInclude(ctx, workingDir, environment, cfg, opts, included, processor)
482 if err != nil {
483 return err
484 }
485 }
486
487 if err := processor.Apply(dict); err != nil {
488 return err
489 }
490
491 // Process extends after includes so base services are fully merged
492 if !opts.SkipExtends {
493 err = ApplyExtends(ctx, cfg, opts, ct, processor)
494 if err != nil {
495 return err
496 }
497
498 }

Callers 2

getExtendsBaseFromFileFunction · 0.85
loadYamlModelFunction · 0.85

Calls 11

ApplyMethod · 0.95
MergeFunction · 0.92
EnforceUnicityFunction · 0.92
ValidateFunction · 0.92
CanonicalFunction · 0.92
fixEmptyNotNullFunction · 0.85
ApplyIncludeFunction · 0.85
ApplyExtendsFunction · 0.85
OmitEmptyFunction · 0.85
warnObsoleteVersionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…