Unofficial Go library for the Wordnik API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
account.go
account_test.go
client.go
client_test.go
envKey_test.go
queryOptions.go
queryOptions_test.go
word.go
wordList.go
wordList_test.go
wordLists.go
wordLists_test.go
word_test.go
words.go
words_test.go

README.md

go-wordnik

Unofficial Go library for the Wordnik API

Build Status Go Report Card Documentation

Requirements

Go version >= 1.8

Basic Usage

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

}

Configuring Queries

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")
    }
  }

Running The Tests

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

License

This project is licensed under the MIT License - see the LICENSE file for details