Skip to content

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.

@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

❌ 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