Skip to content

feat: Set default values for all addressable structs #58

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gitsang
Copy link

@gitsang gitsang commented Jul 3, 2025

Set default values for all addressable structs when struct fields has default tag.

type OtherStruct struct {
  Name string `default:"hello"`
}

type Sample struct {
  Maps map[string]OtherStruct
}

func main() {
	obj := &Sample{
		Maps: map[string]OtherStruct{
			"hello": {},
		},
	}
	if err := defaults.Set(obj); err != nil {
		panic(err)
	}
}

Previously, in this situation, it would output {"maps": {"hello": {}}} and the default value would not be set to OtherStruct.

After modification, it will output {"maps": {"hello": {"name": "hello"}}}

I don't know if this is the expected behavior, but I think the default value should take effect anywhere, which is more intuitive.

Copy link

codecov bot commented Jul 3, 2025

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.05%. Comparing base (abebf4b) to head (b5a101c).

Files with missing lines Patch % Lines
defaults.go 78.57% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   95.97%   96.05%   +0.07%     
==========================================
  Files           2        2              
  Lines         149      152       +3     
==========================================
+ Hits          143      146       +3     
  Misses          3        3              
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant