Make DefaultClient a method that returns the global default client

I made this a method to prevent other users from reassigning the
previously exported DefaultClient, e.g. doing something like:

```go
reddit.DefaultClient = nil
```

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-11-01 22:25:13 -05:00
parent 8fe2410f4a
commit 78dc97a8d5
6 changed files with 13 additions and 9 deletions
+2 -2
View File
@@ -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.
posts, resp, 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,
},
@@ -36,7 +36,7 @@ func run() (err error) {
// The After option sets the id of an item that Reddit
// will use as an anchor point for the returned listing.
posts, _, 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: resp.After,