-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Feature Request (with code to do it!) OmitEmpty on structures #54
Comments
The code isn't right, but the idea is fine. |
Why isn't it right - it worked when I added it?
|
And I should have said it earlier, thanks for sharing yaml! It's great stuff!!
|
The problem in the sample code is that only fields that are exported should be considered. I have the same logic working in the mgo/bson parser and will copy it over. |
Thanks
|
if a structure has the
yam:key,omitempty
tag, why not omit it as well if it's members are all empty:To do so, simply add the following snippet to isZero in yaml.go - where we check for a structure and then recursively call isZero on all of it's members...
case reflect.Struct:
for i := 0; i < v.NumField(); i++ {
p := v.Field(i)
if !isZero(p) {
return false
}
}
return true
The text was updated successfully, but these errors were encountered: