mergeConfigFromFile merges file config values into the base config. The keys map indicates which fields were present in the file, allowing zero values (like max-in-flight: 0) to override defaults. Uses reflection to iterate over fields based on their JSON tags.
(base, file *config.Config, keys map[string]struct{})
| 259 | // zero values (like max-in-flight: 0) to override defaults. |
| 260 | // Uses reflection to iterate over fields based on their JSON tags. |
| 261 | func mergeConfigFromFile(base, file *config.Config, keys map[string]struct{}) { |
| 262 | baseVal := reflect.ValueOf(base).Elem() |
| 263 | fileVal := reflect.ValueOf(file).Elem() |
| 264 | baseType := baseVal.Type() |
| 265 | |
| 266 | for i := range baseType.NumField() { |
| 267 | field := baseType.Field(i) |
| 268 | jsonTag := strings.Split(field.Tag.Get("json"), ",")[0] |
| 269 | if jsonTag == "" || jsonTag == "-" { |
| 270 | continue |
| 271 | } |
| 272 | if _, ok := keys[jsonTag]; ok { |
| 273 | baseVal.Field(i).Set(fileVal.Field(i)) |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // validateConfig validates the config after all sources have been merged. |
| 279 | func validateConfig(cfg *config.Config) error { |