Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(os/gcfg): adjust priority of env|cmd higer than config file (#4074)#4587

Merged
hailaz merged 3 commits intogogf:masterfrom
yangyanqing:fix/getwithenv
Jan 9, 2026
Merged

fix(os/gcfg): adjust priority of env|cmd higer than config file (#4074)#4587
hailaz merged 3 commits intogogf:masterfrom
yangyanqing:fix/getwithenv

Conversation

@yangyanqing
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetWithEnv and GetWithCmd methods 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.

@hailaz hailaz merged commit caea7ea into gogf:master Jan 9, 2026
18 checks passed
lingcoder added a commit to lingcoder/gf that referenced this pull request Jan 21, 2026
…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)
lingcoder added a commit to lingcoder/gf that referenced this pull request Jan 21, 2026
…Env and GetWithCmd

This reverts the behavior change introduced in PR gogf#4587 (commit caea7ea).

The priority order is restored to v2.9.7 behavior:
- config file > environment variable > default value (GetWithEnv)
- config file > command line option > default value (GetWithCmd)

Closes gogf#4074
gqcn pushed a commit that referenced this pull request Jan 21, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants