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

Feature Request (with code to do it!) OmitEmpty on structures #54

Closed
rabarar opened this issue Nov 11, 2014 · 5 comments
Closed

Feature Request (with code to do it!) OmitEmpty on structures #54

rabarar opened this issue Nov 11, 2014 · 5 comments

Comments

@rabarar
Copy link

rabarar commented Nov 11, 2014

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

@niemeyer
Copy link
Contributor

The code isn't right, but the idea is fine.

@rabarar
Copy link
Author

rabarar commented Nov 14, 2014

Why isn't it right - it worked when I added it?

On Nov 14, 2014, at 4:29 AM, Gustavo Niemeyer notifications@github.com wrote:

The code isn't right, but the idea is fine.


Reply to this email directly or view it on GitHub.

@rabarar
Copy link
Author

rabarar commented Nov 14, 2014

And I should have said it earlier, thanks for sharing yaml! It's great stuff!!

On Nov 14, 2014, at 4:29 AM, Gustavo Niemeyer notifications@github.com wrote:

The code isn't right, but the idea is fine.


Reply to this email directly or view it on GitHub.

@niemeyer
Copy link
Contributor

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.

@rabarar
Copy link
Author

rabarar commented Jan 16, 2015

Thanks

On Jan 16, 2015, at 1:46 PM, Gustavo Niemeyer notifications@github.com wrote:

Closed #54 via 26b8825.


Reply to this email directly or view it on GitHub.

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

No branches or pull requests

2 participants