From 4eeb46d6b9bd9d6c588cb1934695002fe39e2221 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 13 Feb 2017 17:16:31 +0000 Subject: [PATCH] Search for large images only. Fix httpClient reference. Fix logging when no error and no results --- .../matrix-org/go-neb/services/google/google.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/google/google.go b/src/github.com/matrix-org/go-neb/services/google/google.go index 030a861..630722c 100644 --- a/src/github.com/matrix-org/go-neb/services/google/google.go +++ b/src/github.com/matrix-org/go-neb/services/google/google.go @@ -145,7 +145,7 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { q.Set("q", query) // String to search for q.Set("num", "1") // Just return 1 image result q.Set("start", "1") // No search result offset - q.Set("imgSize", "medium") // Just search for medium size images + q.Set("imgSize", "large") // Just search for medium size images q.Set("searchType", "image") // Search for images q.Set("key", s.APIKey) // Set the API key for the request @@ -154,7 +154,7 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { u.RawQuery = q.Encode() // log.Info("Request URL: ", u) - res, err := http.Get(u.String()) + res, err := httpClient.Get(u.String()) if res != nil { defer res.Body.Close() } @@ -167,8 +167,10 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { var searchResults googleSearchResults // log.Info(response2String(res)) - if err := json.NewDecoder(res.Body).Decode(&searchResults); err != nil || len(searchResults.Items) < 1 { - return nil, fmt.Errorf("No images found - %s", err.Error()) + if err := json.NewDecoder(res.Body).Decode(&searchResults); err != nil { + return nil, fmt.Errorf("ERROR - %s", err.Error()) + } else if len(searchResults.Items) < 1 { + return nil, fmt.Errorf("No images found") } // Return only the first search result