fix(os/gcfg): adjust priority of env|cmd higer than config file (#4074)#4587
fix(os/gcfg): adjust priority of env|cmd higer than config file (#4074)#4587hailaz merged 3 commits intogogf:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the priority of environment variables and command-line arguments to be higher than configuration file values in the gcfg package. Previously, these methods would first check the config file, then fall back to env/cmd values. Now they check env/cmd values first, giving them precedence over config file settings.
Key Changes:
- Simplified
GetWithEnvandGetWithCmdmethods to check env/cmd sources first before falling back to config file - Removed complex error handling logic that checked for
gcode.CodeNotFound - Updated example tests to reflect the new priority behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| os/gcfg/gcfg.go | Refactored GetWithEnv and GetWithCmd to check environment/command sources first, then fall back to config file; removed unused imports |
| os/gcfg/gcfg_z_example_test.go | Updated example tests to demonstrate the new priority behavior, checking for absence of env/cmd values before they are set |
Note: The documentation comments for GetWithEnv (lines 114-116) and GetWithCmd (lines 126-128) in os/gcfg/gcfg.go are now outdated and should be updated to reflect that env/cmd values are checked first, not as fallbacks. However, these lines are outside the changed regions in this PR.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tWithCmd This reverts the behavior change introduced in gogf#4587 which changed the priority order of configuration sources. Original behavior (restored): - GetWithEnv: config file > environment variable > default - GetWithCmd: config file > command line > default The change in gogf#4587 was a breaking change that affected existing code relying on the original priority order. Closes gogf#4074 (reverts the fix approach)
…Env and GetWithCmd (#4647) ## Summary - Reverts the behavior change introduced in PR #4587 (commit caea7ea) - Restores v2.9.7 priority behavior: - `GetWithEnv`: config file > environment variable > default value - `GetWithCmd`: config file > command line option > default value ## Related Issue Closes #4074 ## Changes - `os/gcfg/gcfg.go`: Restore original logic that checks config file first, then falls back to env/cmd - `os/gcfg/gcfg_z_example_test.go`: Restore original example test expectations
No description provided.