-
Notifications
You must be signed in to change notification settings - Fork 11
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
collection: Support collecting posts #14
Conversation
This adds support for deleting collections. Resolves #1.
Rather than accepting a naked string, accept a DeleteCollectionParams struct so that new optional parameters can be added in the future without breaking the API.
This adds support for moving posts to a collection. This change relies on #13 so that we can create and delete collections during tests. Couple notes: - CollectPosts accepts a single struct rather than an alias and a list of structs. This makes it easy to add new optional parameters in the future. - We're passing `[]*CollectPost` around rather than `*[]CollectPost` which is done in some of the existing APIs. The reasoning for this is: - Idiomatically, slices are passed by-value (`[]foo`) rather than by-pointer (`*[]foo`) because slices are already reference types. Plus they're really cheap to copy since they're just a triple: pointer, length, and capacity ([related blog post][1]). We need pointers to slices only when we're trying to modify the original slice reference and don't have the ability to return a slice, like with `json.Unmarshal` (see also [this post][2]). - If we're trying to reduce copying, `[]*foo` is better than `[]foo` because otherwise `foo` will be copied when manipulating or accessing entries in the slice (like ranging over it). Existing APIs were left as-is to avoid breaking them. I can switch to `*[]CollectPost` if you'd prefer that but `[]*CollectPost` is more idiomatic. [1]: https://blog.golang.org/go-slices-usage-and-internals#TOC_4. [2]: https://blog.golang.org/slices#TOC_5. Resolves #4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abhinav, thanks for this.
If your still interested in contributing this change there are a couple things we should change.
- the parameters don't really need to be structs, for DeleteCollection and CollectPost
- collection: Add support for deletion #13 has been merged
- there are a few merge conflicts from recent changes to the test file, or related to collection: Add support for deletion #13 merging ( I haven't checked yet )
endpoint := "/collections/" + sp.Alias + "/collect" | ||
|
||
var p []*CollectPostResult | ||
env, err := c.post(endpoint, sp.Posts, &p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to pass the address here as slices are reference types already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to pass a pointer for the JSON unmarshaler to fill it with a decoded value. So json.Unmarshal requires the result argument to always be a pointer.
I want to hold off on anymore changes to this for now, as I implemented the same thing locally and would like to combine the best of both implementations. |
ok 👍 should we close this then? |
@thebaer @robjloranger Feel free to close this PR. |
we can reopen if needed |
Note: This PR includes changes from #13 because the change being
proposed here relies on functionality added in #13. The change itself
can be reviewed in its own commit. The commit message for it is
repeated below.
This adds support for moving posts to a collection. This change relies
on #13 so that we can create and delete collections during tests.
Couple notes:
CollectPosts accepts a single struct rather than an alias and a list
of structs. This makes it easy to add new optional parameters in the
future.
We're passing
[]*CollectPost
around rather than*[]CollectPost
which is done in some of the existing APIs. The reasoning for this is
Idiomatically, slices are passed by-value (
[]foo
) rather thanby-pointer (
*[]foo
) because slices are already reference types.Plus they're really cheap to copy since they're just a triple:
pointer, length, and capacity (related blog post). We need
pointers to slices only when we're trying to modify the original
slice reference and don't have the ability to return a slice, like
with
json.Unmarshal
(see also this post).If we're trying to reduce copying,
[]*foo
is better than[]foo
because otherwise
foo
will be copied when manipulating oraccessing entries in the slice (like ranging over it).
Existing APIs were left as-is to avoid breaking them. I can switch to
*[]CollectPost
if you'd prefer that but[]*CollectPost
is moreidiomatic.
Resolves #4.