Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/gcfg: priority of env should be higer than file. #4074

Open
yangyanqing opened this issue Dec 24, 2024 · 2 comments
Open

os/gcfg: priority of env should be higer than file. #4074

yangyanqing opened this issue Dec 24, 2024 · 2 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted

Comments

@yangyanqing
Copy link
Contributor

Go version

go version go1.23.4 windows/amd64

GoFrame version

2.8.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

With v2.8.3, config by file had higher than config by env.

What did you see happen?

func (c *Config) Get(ctx context.Context, pattern string, def ...interface{}) (*gvar.Var, error) {
	var (
		err   error
		value interface{}
	)
	value, err = c.adapter.Get(ctx, pattern)
	if err != nil {
		return nil, err
	}
	if value == nil {
		if len(def) > 0 {
			return gvar.New(def[0]), nil
		}
		return nil, nil
	}
	return gvar.New(value), nil
}

What did you expect to see?

In general, config by env should have higher priority than config by config.yaml.
Spring cloud and viper think so too.

@yangyanqing yangyanqing added the bug It is confirmed a bug, but don't worry, we'll handle it. label Dec 24, 2024
@gqcn
Copy link
Member

gqcn commented Dec 26, 2024

@yangyanqing Yes, I think so too. It should be updated in method GetWithEnv and GetWithCmd for package gcfg:

  • func (c *Config) GetWithEnv(ctx context.Context, pattern string, def ...interface{}) (*gvar.Var, error) {
  • func (c *Config) GetWithCmd(ctx context.Context, pattern string, def ...interface{}) (*gvar.Var, error) {

Thanks for your proposal!

Copy link

Hello @yangyanqing. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @yangyanqing。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted
Projects
None yet
Development

No branches or pull requests

2 participants