Load reads a ConfigDetails and returns a fully loaded configuration
(configDetails types.ConfigDetails, opt ...func(*Options))
| 77 | |
| 78 | // Load reads a ConfigDetails and returns a fully loaded configuration |
| 79 | func Load(configDetails types.ConfigDetails, opt ...func(*Options)) (*types.Config, error) { |
| 80 | if len(configDetails.ConfigFiles) < 1 { |
| 81 | return nil, errors.New("no files specified") |
| 82 | } |
| 83 | |
| 84 | options := &Options{ |
| 85 | Interpolate: &interp.Options{ |
| 86 | Substitute: template.Substitute, |
| 87 | LookupValue: configDetails.LookupEnv, |
| 88 | TypeCastMapping: interpolateTypeCastMapping, |
| 89 | }, |
| 90 | } |
| 91 | |
| 92 | for _, op := range opt { |
| 93 | op(options) |
| 94 | } |
| 95 | |
| 96 | configs := []*types.Config{} |
| 97 | var err error |
| 98 | |
| 99 | for _, file := range configDetails.ConfigFiles { |
| 100 | configDict := file.Config |
| 101 | version := schema.Version(configDict) |
| 102 | if configDetails.Version == "" { |
| 103 | configDetails.Version = version |
| 104 | } |
| 105 | if configDetails.Version != version { |
| 106 | return nil, fmt.Errorf("version mismatched between two composefiles : %v and %v", configDetails.Version, version) |
| 107 | } |
| 108 | |
| 109 | if err := validateForbidden(configDict); err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | |
| 113 | if !options.SkipInterpolation { |
| 114 | configDict, err = interpolateConfig(configDict, *options.Interpolate) |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if !options.SkipValidation { |
| 121 | if err := schema.Validate(configDict, configDetails.Version); err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | cfg, err := loadSections(configDict, configDetails) |
| 127 | if err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | cfg.Filename = file.Filename |
| 131 | if options.discardEnvFiles { |
| 132 | for i := range cfg.Services { |
| 133 | cfg.Services[i].EnvFile = nil |
| 134 | } |
| 135 | } |
| 136 |
searching dependent graphs…