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

FillStructWithDefault did not support setting default value recursively for nested struct #3221

Closed
zhangyuyu opened this issue Dec 20, 2023 · 1 comment · Fixed by #3224
Closed
Assignees
Labels
enhancement help wanted planned This issue/proposal is planned into our next steps.

Comments

@zhangyuyu
Copy link
Contributor

1. What version of Go and system type/arch are you using?

go version go1.21.3 darwin/arm64

2. What version of GoFrame are you using?

2.6.0

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

func main() {
	cfg := &Config{}

	gutil.FillStructWithDefault(cfg)
	fmt.Println(fmt.Sprintf("%+v", cfg))
}

// Config configuration for whole application
type Config struct {
	Name    string  `json:"name" d:"zhangsan"`
	Enable1 bool    `json:"enable1" d:"true"`
	Enable2 bool    `json:"enable2"`
	Service Service `json:"service"`
}

// Service configuration for service
type Service struct {
	Env         string `json:"env"`
	AppID       string `json:"appID" d:"testApp"` 
	IsDebug     bool   `json:"isDebug" d:"true"`  
	EnableCache bool   `json:"enable_cache"`  
}

5. What did you expect to see?

When struct Config have a nested struct Service, it can set default value for both Config and Service.
&{Name:zhangsan Enable1:true Enable2:false Service:{Env: AppID:testApp IsDebug:true EnableCache:false}}

6. What did you see instead?

It only set the default value for outer Struct Config, ignore the default tag for inner struct Service.
&{Name:zhangsan Enable1:true Enable2:false Service:{Env: AppID: IsDebug:false EnableCache:false}}

@gqcn gqcn added enhancement help wanted planned This issue/proposal is planned into our next steps. labels Dec 20, 2023
Copy link

Hello @zhangyuyu. 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!
你好 @zhangyuyu。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

oldme-git added a commit to oldme-git/gf that referenced this issue Dec 21, 2023
oldme-git added a commit to oldme-git/gf that referenced this issue Dec 21, 2023
@gqcn gqcn mentioned this issue Dec 21, 2023
oldme-git added a commit to oldme-git/gf that referenced this issue Dec 22, 2023
oldme-git added a commit to oldme-git/gf that referenced this issue Dec 22, 2023
@oldme-git oldme-git self-assigned this Dec 22, 2023
gqcn pushed a commit that referenced this issue Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants