matryer/goblueprints

Ch. 4 thesaurus, description incorrect

Closed this issue · 1 comments

Code

package thesaurus
   import (
     "encoding/json"
     "errors"
     "net/http"
   )
   type BigHugh struct {
     APIKey string
   }
   type synonyms struct {
     Noun *words `json:"noun"`
     Verb *words `json:"verb"`
   }
   type words struct {
     Syn []string `json:"syn"`
   }
   func (b *BigHugh) Synonyms(term string) ([]string, error) {
     var syns []string
     response, err := http.Get("http://words.bighugelabs.com/api/2/"
   + b.APIKey + "/" + term + "/json")
     if err != nil {
       return syns, errors.New("bighugh: Failed when looking for
   synonyms for \"" + term + "\"" + err.Error())
     }
     var data synonyms
     defer response.Body.Close()
     if err := json.NewDecoder(response.Body).Decode(&data); err !=
   nil {
       return syns, err
     }
     syns = append(syns, data.Noun.Syn...)
     syns = append(syns, data.Verb.Syn...)
     return syns, nil
 }

Text

"The Synonyms method takes a term argument and uses http.Get to make a web request to the API endpoint in which the URL contains not only the API key value, but also the term value itself. If the web request fails for some reason, we will make a call to log.Fatalln, [...]"

So the code returns an error while description says we call log.Fatalln

Thank you.