Created
December 28, 2022 10:08
-
-
Save bontusss/96f8785f4e2c4ec55c455872fac89cac to your computer and use it in GitHub Desktop.
thesaurus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"errors" | |
"net/http" | |
) | |
type BigHuge struct { | |
APIKEY string | |
} | |
type synonyms struct { | |
Noun *words `json:"noun"` | |
Verb *words `json:"verb"` | |
} | |
type words struct { | |
Syn []string `json:"syn"` | |
} | |
func (b *BigHuge) Synonymns(term string) ([]string, error) { | |
var syns []string | |
response, err := http.Get("https://words.bighugelabs.com/api/2/" + b.APIKEY + "/" + term + "/json") | |
if err != nil { | |
return syns, errors.New("bighuge: 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 | |
} | |
if data.Noun != nil { | |
syns = append(syns, data.Noun.Syn...) | |
} | |
if data.Verb != nil { | |
syns = append(syns, data.Verb.Syn...) | |
} | |
return syns, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment