Skip to content

feat(os/gcfg): add GetEffective method with standard config priority#4673

Merged
gqcn merged 2 commits intogogf:masterfrom
lingcoder:feature/gcfg-get-effective
Feb 26, 2026
Merged

feat(os/gcfg): add GetEffective method with standard config priority#4673
gqcn merged 2 commits intogogf:masterfrom
lingcoder:feature/gcfg-get-effective

Conversation

@lingcoder
Copy link
Copy Markdown
Contributor

Summary

  • Add GetEffective and MustGetEffective methods following 12-Factor App config priority
  • Priority: Command line > Environment variables > Config file > Default value
  • Add clarifying notes to existing GetWithEnv/GetWithCmd methods
  • Add comprehensive unit tests

Test plan

  • All gcfg unit tests pass (44 tests)
  • New Test_GetEffective covers 6 scenarios:
    • Config file only
    • Env overrides config
    • Cmd overrides env
    • Default value fallback
    • Empty string override (industry standard)
    • Key only in env

Closes #4650

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
Copy link
Copy Markdown
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

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 / MustGetEffective implementing priority: cmd > env > config > default.
  • Clarified precedence behavior in GetWithEnv / GetWithCmd doc comments.
  • Added unit test coverage for GetEffective scenarios.

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.

@gqcn gqcn self-requested a review February 11, 2026 06:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gqcn gqcn merged commit 1ab0b18 into gogf:master Feb 26, 2026
18 checks passed
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.

os/gcfg: 新增支持标准配置优先级的获取方法

3 participants