feat(os/gcfg): add GetEffective method with standard config priority#4673
Merged
gqcn merged 2 commits intogogf:masterfrom Feb 26, 2026
Merged
feat(os/gcfg): add GetEffective method with standard config priority#4673gqcn merged 2 commits intogogf:masterfrom
gqcn merged 2 commits intogogf:masterfrom
Conversation
Add GetEffective and MustGetEffective methods that follow 12-Factor App methodology for configuration priority: Command line > Environment variables > Config file > Default value This is the standard behavior in frameworks like Spring Boot and Viper, where higher priority sources can override lower priority ones. Key changes: - Add GetEffective/MustGetEffective with standard priority - Use ContainsOpt to properly handle empty string from command line - Add clarifying notes to GetWithEnv/GetWithCmd about their priority - Add comprehensive unit tests Closes gogf#4650
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new configuration accessor to os/gcfg that follows 12-Factor-style precedence so runtime sources can override config values.
Changes:
- Added
(*gcfg.Config).GetEffective/MustGetEffectiveimplementing priority: cmd > env > config > default. - Clarified precedence behavior in
GetWithEnv/GetWithCmddoc comments. - Added unit test coverage for
GetEffectivescenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| os/gcfg/gcfg.go | Introduces GetEffective/MustGetEffective and updates docs for existing methods to clarify precedence. |
| os/gcfg/gcfg_z_unit_basic_test.go | Adds Test_GetEffective covering override precedence and default/empty-string behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
gqcn
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GetEffectiveandMustGetEffectivemethods following 12-Factor App config priorityGetWithEnv/GetWithCmdmethodsTest plan
Test_GetEffectivecovers 6 scenarios:Closes #4650