Skip to content

Instantly share code, notes, and snippets.

@dimus
Last active December 1, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimus/68f8e7124d15239d7c2b1b6537ce296d to your computer and use it in GitHub Desktop.
Save dimus/68f8e7124d15239d7c2b1b6537ce296d to your computer and use it in GitHub Desktop.
TaxonWorks API
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/gnames/gnlib/encode"
)
const (
url = "https://sfg.taxonworks.org/api/v1/taxon_names?nomenclature_group[]=Family&project_token=adhBi59dc13U7RxbgNE5HQ"
)
type recordTW struct {
ID int `json:"id"`
Name string `json:"name"`
Code string `json:"nomenclatural_code"`
Rank string `json:"rank_string"`
NameString string `json:"name_string"`
}
func main() {
// lets say we only care to grab the fields that are in recordTW structure
var response []recordTW
resp, _ := http.Get(url)
respBytes, _ := ioutil.ReadAll(resp.Body)
_ = encode.GNjson{Pretty: true}.Decode(respBytes, &response)
for i, rec := range response {
fmt.Printf("%d: %s\n", i, rec.NameString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment