buildConfig builds the config from CLI values with correct precedence: defaults < config file < env vars/CLI flags. Kong has already applied env vars and CLI flags to the cli struct.
(cli *CLI)
| 95 | // defaults < config file < env vars/CLI flags. |
| 96 | // Kong has already applied env vars and CLI flags to the cli struct. |
| 97 | func buildConfig(cli *CLI) (*config.Config, error) { |
| 98 | // Step 1: Start with defaults |
| 99 | cfg := newConfigWithDefaults() |
| 100 | |
| 101 | // Step 2: Apply config file values (overrides defaults) |
| 102 | if cli.ConfigFile != "" { |
| 103 | fileCfg, keys, err := loadConfigFile(cli.ConfigFile) |
| 104 | if err != nil { |
| 105 | return nil, fmt.Errorf("failed to load config: %w", err) |
| 106 | } |
| 107 | mergeConfigFromFile(cfg, fileCfg, keys) |
| 108 | } |
| 109 | |
| 110 | // Step 3: Apply CLI/env values (overrides config file) |
| 111 | applyCLIOverrides(cfg, cli) |
| 112 | |
| 113 | // Step 4: Validate |
| 114 | if err := validateConfig(cfg); err != nil { |
| 115 | return nil, fmt.Errorf("failed to validate config: %w", err) |
| 116 | } |
| 117 | |
| 118 | return cfg, nil |
| 119 | } |
| 120 | |
| 121 | func runController(cfg *config.Config) error { |
| 122 | ctx := signals.SetupSignalHandler() |