From 407ee432a3cfe89fbf5d40124df3bca6df63eab4 Mon Sep 17 00:00:00 2001 From: Vartan Benohanian Date: Fri, 21 Aug 2020 15:31:15 -0400 Subject: [PATCH] Change doc comment, some very minor tweaks Signed-off-by: Vartan Benohanian --- reddit/gold.go | 2 +- reddit/reddit-options.go | 8 ++++---- reddit/reddit.go | 8 ++------ reddit/subreddit.go | 10 ++++++++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/reddit/gold.go b/reddit/gold.go index e25b367..56b825a 100644 --- a/reddit/gold.go +++ b/reddit/gold.go @@ -11,7 +11,7 @@ import ( // GoldService handles communication with the gold // related methods of the Reddit API. // -// Reddit API docs: https://www.reddit.com/dev/api/#section_collections +// Reddit API docs: https://www.reddit.com/dev/api/#section_gold type GoldService struct { client *Client } diff --git a/reddit/reddit-options.go b/reddit/reddit-options.go index ae6221b..555584d 100644 --- a/reddit/reddit-options.go +++ b/reddit/reddit-options.go @@ -16,19 +16,19 @@ type Opt func(*Client) error // GO_REDDIT_CLIENT_USERNAME to set the client's username. // GO_REDDIT_CLIENT_PASSWORD to set the client's password. func FromEnv(c *Client) error { - if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_ID"); ok { + if v := os.Getenv("GO_REDDIT_CLIENT_ID"); v != "" { c.ID = v } - if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_SECRET"); ok { + if v := os.Getenv("GO_REDDIT_CLIENT_SECRET"); v != "" { c.Secret = v } - if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_USERNAME"); ok { + if v := os.Getenv("GO_REDDIT_CLIENT_USERNAME"); v != "" { c.Username = v } - if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_PASSWORD"); ok { + if v := os.Getenv("GO_REDDIT_CLIENT_PASSWORD"); v != "" { c.Password = v } diff --git a/reddit/reddit.go b/reddit/reddit.go index d5c95cc..c44e241 100644 --- a/reddit/reddit.go +++ b/reddit/reddit.go @@ -253,17 +253,13 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res if err != nil { return nil, err } + defer resp.Body.Close() if c.onRequestCompleted != nil { c.onRequestCompleted(req, resp) } response := newResponse(resp) - defer func() { - if rerr := response.Body.Close(); err == nil { - err = rerr - } - }() err = CheckResponse(resp) if err != nil { @@ -284,7 +280,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res } } - return response, err + return response, nil } // id returns the client's Reddit ID. diff --git a/reddit/subreddit.go b/reddit/subreddit.go index a881ffc..c6d47f7 100644 --- a/reddit/subreddit.go +++ b/reddit/subreddit.go @@ -91,6 +91,8 @@ func (s *SubredditService) getPosts(ctx context.Context, sort string, subreddit // HotPosts returns the hottest posts from the specified subreddit. // To search through multiple, separate the names with a plus (+), e.g. "golang+test". // If none are defined, it returns the ones from your subscribed subreddits. +// To search through all, just specify "all". +// To search through all and filter out subreddits, provide "all-name1-name2". // Note: when looking for hot posts in a subreddit, it will include the stickied // posts (if any) PLUS posts from the limit parameter (25 by default). func (s *SubredditService) HotPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) { @@ -100,6 +102,8 @@ func (s *SubredditService) HotPosts(ctx context.Context, subreddit string, opts // NewPosts returns the newest posts from the specified subreddit. // To search through multiple, separate the names with a plus (+), e.g. "golang+test". // If none are defined, it returns the ones from your subscribed subreddits. +// To search through all, just specify "all". +// To search through all and filter out subreddits, provide "all-name1-name2". func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) { return s.getPosts(ctx, "new", subreddit, opts) } @@ -107,6 +111,8 @@ func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts // RisingPosts returns the rising posts from the specified subreddit. // To search through multiple, separate the names with a plus (+), e.g. "golang+test". // If none are defined, it returns the ones from your subscribed subreddits. +// To search through all, just specify "all". +// To search through all and filter out subreddits, provide "all-name1-name2". func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) { return s.getPosts(ctx, "rising", subreddit, opts) } @@ -114,6 +120,8 @@ func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, op // ControversialPosts returns the most controversial posts from the specified subreddit. // To search through multiple, separate the names with a plus (+), e.g. "golang+test". // If none are defined, it returns the ones from your subscribed subreddits. +// To search through all, just specify "all". +// To search through all and filter out subreddits, provide "all-name1-name2". func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) { return s.getPosts(ctx, "controversial", subreddit, opts) } @@ -121,6 +129,8 @@ func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit str // TopPosts returns the top posts from the specified subreddit. // To search through multiple, separate the names with a plus (+), e.g. "golang+test". // If none are defined, it returns the ones from your subscribed subreddits. +// To search through all, just specify "all". +// To search through all and filter out subreddits, provide "all-name1-name2". func (s *SubredditService) TopPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) { return s.getPosts(ctx, "top", subreddit, opts) }