Revamp listing decoding, include after/before anchors in response

Now, instead of returning an object containing a list of results + the
anchors, we return just the list. The anchors are available in the
response object. Much cleaner this way in my opinion

go-github and godo do it this way too. They include some meta
information in the returned response objects

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-08-29 14:20:30 -04:00
parent 37e712b334
commit 2a1806ec33
15 changed files with 520 additions and 579 deletions
+7 -4
View File
@@ -84,7 +84,7 @@ func (s *PostService) Get(ctx context.Context, id string) (*PostAndComments, *Re
// Duplicates returns the post with the id, and a list of its duplicates.
// id is the ID36 of the post, not its full id.
// Example: instead of t3_abc123, use abc123.
func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDuplicatePostOptions) (*Post, *Posts, *Response, error) {
func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDuplicatePostOptions) (*Post, []*Post, *Response, error) {
path := fmt.Sprintf("duplicates/%s", id)
path, err := addOptions(path, opts)
if err != nil {
@@ -96,14 +96,17 @@ func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDupli
return nil, nil, nil, err
}
var root [2]rootListing
var root [2]listing
resp, err := s.client.Do(ctx, req, &root)
if err != nil {
return nil, nil, resp, err
}
post := root[0].Data.Things.Posts[0]
duplicates := root[1].getPosts()
post := root[0].Posts[0]
duplicates := root[1].Posts
resp.After = root[1].after
resp.Before = root[1].after
return post, duplicates, resp, nil
}