From 7f2d534566a0ebae56abe8f1b8f762ec9ea4297f Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Fri, 8 Sep 2017 08:15:37 +0100 Subject: [PATCH] Allow passing a key to the Google Books API --- googlebooks.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/googlebooks.go b/googlebooks.go index a3116c3..d77b69c 100644 --- a/googlebooks.go +++ b/googlebooks.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "encoding/xml" "errors" + "flag" "fmt" "io" "io/ioutil" @@ -14,6 +15,8 @@ import ( "time" ) +var googleAPIKey = flag.String("google-api-key", "", "Google API key") + type googleBooksRefiner struct{} func (r *googleBooksRefiner) Name() string { @@ -155,6 +158,9 @@ func (r *googleBooksRefiner) Lookup(m *Metadata) ([]*Metadata, error) { } values := make(url.Values) values.Set("q", qstr) + if *googleAPIKey != "" { + values.Set("key", *googleAPIKey) + } uri := "http://books.google.com/books/feeds/volumes?" + values.Encode() resp, err := googleBooksGet(uri) if err != nil { -- GitLab