From 3ae13428d8011811de6475e7dbdd62f6d9060be4 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 10 Feb 2017 16:39:00 +0000 Subject: [PATCH] Moved google custom search engine ID in to service config. Cleaned up comments --- .../go-neb/services/google/google.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 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 431227f..17891ff 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 @@ -51,16 +51,18 @@ type googleImage struct { } // Service contains the Config fields for the Google service. -// TODO - move the google custom search engine ID in here! // // Example request: // { -// "api_key": "AIzaSyA4FD39..." +// "api_key": "AIzaSyA4FD39..." +// "cx": "ASdsaijwdfASD..." // } type Service struct { types.DefaultService // The Google API key to use when making HTTP requests to Google. APIKey string `json:"api_key"` + // The Google custom search engine ID + Cx string `json:"cx"` } // Commands supported: @@ -146,12 +148,9 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { q.Set("start", "1") // No search result offset q.Set("imgSize", "medium") // Just search for medium size images q.Set("searchType", "image") // Search for images - // q.set("fileType, "") // Any file format - var key = s.APIKey - - q.Set("key", key) // Set the API key for the request - q.Set("cx", "003141582324323361145:f5zyrk9_8_m") // Set the custom search engine ID + q.Set("key", s.APIKey) // Set the API key for the request + q.Set("cx", s.Cx) // Set the custom search engine ID u.RawQuery = q.Encode() // log.Info("Request URL: ", u) @@ -170,12 +169,6 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { // log.Info(response2String(res)) if err := json.NewDecoder(res.Body).Decode(&searchResults); err != nil || len(searchResults.Items) < 1 { - // Google return a JSON object which has { items: [] } if there are 0 results. - // This fails to be deserialised by Go. - - // TODO -- Find out how to just return an error string (with no formatting) - // return nil, errors.New("No images found") - // return nil, fmt.Errorf("No results - %s", err) return nil, fmt.Errorf("No images found - %s", err.Error()) }