Unofficial Go library for the Wordnik API
Go version >= 1.8
package main
import (
"fmt"
"github.com/rhallora-heidelberg/go-wordnik"
)
func main() {
cl := wordnik.NewClient("<YOUR API KEY>")
pochade, _ := cl.GetWordOfTheDay("2016-04-03")
fmt.Println(pochade.Word, pochade.Definitions)
// pochade [{A rough sketch. wiktionary noun} {A slight, rough sketch which
// can easily be erased for correction. century noun}]
phytop, _ := cl.Search("phytop")
for _, res := range phytop.SearchResults {
fmt.Println(res.Word, res.Count)
}
// phytop 0
// phytoplankton 2192
// phytophagous 25
// phytophthora 23
// phytoplasma 14
}
For endpoints with many optional query parameters, such as Search, this project makes use of the functional options pattern. This means that optional parameters can be set like this:
//...
// Only words with 6 or 7 characters:
response, _ := cl.Search("fru", MinLength(6), MaxLength(7))
// Disable case-sensitive search
response, _ = cl.Search("ora", CaseSensitive(false))
//...
If you need to set the same parameters on a regular basis, you can define your own functions which fit the QueryOption definition in queryOptions.go:
// type QueryOption func(*url.Values)
func LongListOfLongNouns() wordnik.QueryOption {
return func(q *url.Values) {
q.Set("includePartOfSpeech", "noun")
q.Set("minLength", "7")
q.Set("skip", "1")
q.Set("limit", "100")
}
}
In order to run the included tests, you'll need to provide some information via three environment variables: WORDNIK_API_KEY, WORDNIK_TEST_USER, and WORDNIK_TEST_PASS. There are a number of ways to do this, but here's a simple one-off example for the command line:
WORDNIK_API_KEY="your_key" WORDNIK_TEST_USER="your_account" WORDNIK_TEST_PASS="your_password" go test
This project is licensed under the MIT License - see the LICENSE file for details