-
Notifications
You must be signed in to change notification settings - Fork 128
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
Depointerize maps and slices #138
Conversation
@bobrik, would you mind reviewing? @kesselborn, feel free to also have a look. |
d627ec5
to
e983658
Compare
As the zero value for a reference type is nil and becomes empty upon initialization, we do not need to use pointers for maps and structs when it comes to distinguishing omitted and empty JSON values. Other drive-by refactorings include: - Rename Empty{Label,Env} to Empty{labels,Envs} for consistency reasons. - Compare length with == instead of <=. - Fix in-code typos. - Minor cosmetics.
e983658
to
1541534
Compare
LGTM |
👍 LGTM |
@timoreimann @gambol99 I ran into a problem that this PR introduced. With it no longer being a pointer, there's no way to force it to send an empty array as the json annotations have I ran into this because I had an application with |
@rubbish you probably want mesosphere/marathon#1418 |
@bobrik But this isn't about setting it to null, it's about setting it to an empty array. This PR changed it so I can't update an applications' |
What I didn't realize when I put together the PR is that initialized, empty reference types apparently still count as zero values from I believe we should revert the change. To address @bobrik's original concern, we can consider providing accessor methods to make working with pointers more convenient. That should be subject for a different issue, though. Thoughts? |
@rubbish null and empty array should have the same meaning for @timoreimann what about dropping |
@bobrik Dropping See also this blog post that served as a basis for the PR which introduced pointers in go-marathon in the first place. We basically leaned towards the same argumentation at the time. |
Okay looking at your playground example, dropping |
👍 for removing omitempty. It's been troublesome for me in the past. |
On a closer look, the serialized outcome of an uninitialized reference type missing the Even if Marathon treated |
Yeah, this makes sense. I wonder what's the idiomatic way. |
@bobrik I have the feeling that there's no clear idiomatic way. FWIW though, the author of go-github (who wrote the blog post I linked above) believes that the pointer approach is the most idiomatic one. See also his comment. Preparing a reverting PR now. |
Things should be fine again hopefully. If not, please let me know. Apologies for the mess. Beyond simple cases, |
As the zero value for a reference type is nil and becomes empty upon initialization, we do not need to use pointers for maps and structs when it comes to distinguishing omitted and empty JSON values.
Other drive-by refactorings include:
Empty{Label,Env}
toEmpty{labels,Envs}
for consistency reasons.==
instead of<=
.Closes #137.