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:
@@ -20,7 +20,7 @@ func run() (err error) {
|
||||
// Let's get the top 200 posts of r/golang.
|
||||
// Reddit returns a maximum of 100 posts at a time,
|
||||
// so we'll need to separate this into 2 requests.
|
||||
result, _, err := reddit.DefaultClient.Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
|
||||
posts, resp, err := reddit.DefaultClient.Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
|
||||
ListOptions: reddit.ListOptions{
|
||||
Limit: 100,
|
||||
},
|
||||
@@ -30,16 +30,16 @@ func run() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, post := range result.Posts {
|
||||
for _, post := range posts {
|
||||
fmt.Println(post.Title)
|
||||
}
|
||||
|
||||
// The SetAfter option sets the id of an item that Reddit
|
||||
// The After option sets the id of an item that Reddit
|
||||
// will use as an anchor point for the returned listing.
|
||||
result, _, err = reddit.DefaultClient.Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
|
||||
posts, _, err = reddit.DefaultClient.Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
|
||||
ListOptions: reddit.ListOptions{
|
||||
Limit: 100,
|
||||
After: result.After,
|
||||
After: resp.After,
|
||||
},
|
||||
Time: "all",
|
||||
})
|
||||
@@ -47,7 +47,7 @@ func run() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, post := range result.Posts {
|
||||
for _, post := range posts {
|
||||
fmt.Println(post.Title)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user