Go library for http://www.brewerydb.com/ API

brewerydb

brewerydb is a Go library for accessing the BreweryDB API

GoDoc Build StatusCoverage Status

usage

import "github.com/naegelejd/brewerydb"

Construct a new Client using your BreweryDB API key:

client := brewerydb.NewClient("<your API key>")

Then use the available services to access the API. For example:

// Get any random beer
beer, _ := client.Beer.Random(&brewerydb.RandomBeerRequest{ABV: "8"})
fmt.Println(beer.Name, beer.Style.Name)

or

// Get all breweries established in 1983
bs, err := client.Brewery.List(&brewerydb.BreweryListRequest{Established: "1983"})
if err != nil {
    panic(err)
}
for _, b := range bs {
    fmt.Println(b.Name, b.Website)
}

or

// "What is in Dragon's Milk?"
bl, _ := client.Search.Beer("Dragon's Milk", nil)

var beerID string
for _, beer := range bl.Beers {
    if beer.Name == "Dragon's Milk" {
        beerID = beer.ID
    }
}
if beerID == "" {
    panic("Dragon's Milk not found")
}

ingredients, _ := client.Beer.ListIngredients(beerID)
adjuncts, _ := client.Beer.ListAdjuncts(beerID)
fermentables, _ := client.Beer.ListFermentables(beerID)
hops, _ := client.Beer.ListHops(beerID)
yeasts, _ := client.Beer.ListYeasts(beerID)

fmt.Println("Dragon's Milk:")
fmt.Println("  Ingredients:")
for _, ingredient := range ingredients {
    fmt.Println("    " + ingredient.Name)
}
fmt.Println("\n  Adjuncts:")
for _, adjunct := range adjuncts {
    fmt.Println("    " + adjunct.Name)
}
fmt.Println("  Fermentables:")
for _, fermentable := range fermentables {
    fmt.Println("    " + fermentable.Name)
}
fmt.Println("  Hops:")
for _, hop := range hops {
    fmt.Println("    " + hop.Name)
}
fmt.Println("  Yeasts:")
for _, yeast := range yeasts {
    fmt.Println("    " + yeast.Name)
}

status

This library is under development. Please feel free to suggest design changes or report issues.

license

This library is distributed under the BSD-style license found in the LICENSE file.

viewsviews 24h

Owner
Joseph Naegele
I write programs.
Joseph Naegele
Comments
  • Docs

    Docs

    This PR adds a lot of reference links in the comments to the API pages on the brewerydb website. Once merged, you can see the links in godoc.

    About a third of all methods have had links added.

    This makes some progress on #11.

  • Service methods have confusing names

    Service methods have confusing names

    (For example) I don't think the EventService should allow retrieving Events using List and Get when adding new ones or updating/deleting existing ones requires AddEvent, UpdateEvent, or DeleteEvent, respectively. The EventService also has methods like ListBeers, AddBeer, UpdateBrewery, etc.

    Should the methods called List and Get be renamed to include the type of object being retrieved, or should the Add..., Update..., and Delete... methods have the object type removed from their name for each service?

    Option 1:

    client.Event.List -> client.Event.ListEvents
    client.Event.Get  -> client.Event.GetEvent
    

    or Option 2:

    client.Event.AddEvent    -> client.Event.Add
    client.Event.UpdateEvent -> client.Event.Update
    client.Event.DeleteEvent -> client.Event.Delete
    

    For reference, the BeerService currently looks like option 2.

  • All Add and Update endpoints should ensure their parameters are not nil

    All Add and Update endpoints should ensure their parameters are not nil

    All Add/Update endpoints accept a pointer to a brewerydb type which then gets encoded using go-querystring. Each of these methods should check that said pointer is not nil before creating an *http.Request.

  • switching to Google's querystring package

    switching to Google's querystring package

    this cleans up the struct field tags for every struct that gets encoded into a query string (json -> url). It also allows for cleanly using the basic types (e.g. Beer, Event) as encodable "request" types, e.g. UpdateBeer(beerID string, b *Beer).

    Closes #9.

  • Weak URL querystring encoding

    Weak URL querystring encoding

    The current support for encoding "request" structs as URL query strings is weak (because I hacked it out). The easiest way to solve this is to use github.com/google/go-querystring/query. I've evaluated it and decided that it would solve many problems at once:

    1. Proper support for encoding embedded structs
    2. Better struct tags for fields that should vs shouldn't be encoded (currently just using json, which is inaccurate)
    3. Unification of "query" structs. Some methods require a query struct like BeerChangeRequest for adding new beers or updating existing ones, when really they should just take a Beer struct. This requires omitting some fields in the Beer struct during encoding, e.g. ID, CreateDate, etc.
  • All

    All "Y/N" string fields are not idomatic Go

    Ideally, all "Y/N" fields should be of type bool in the Go API. I guess this would require special JSON decoding/encoding.

    On this note, it would be nice if all the "year" and "postalCode" fields could be ints in Go but still encode to strings in JSON.

  • Duplicate code for all instances of each type of HTTP request

    Duplicate code for all instances of each type of HTTP request

    Every endpoint has a lot of duplicate code for:

    • creating the request with url-encoded values
    • making the request and checking errors
    • checking the HTTP response
    • decoding JSON and checking errors

    It'd be nice to consolidate this logic.

  • Inconsistent

    Inconsistent "List" types

    Many endpoints return a "list" of objects, usually paginated. The current API has three different "list" types:

    • normal slice of objects
    • a thin struct wrapper containing a slice of objects, one for each "page"
    • a struct wrapper that supports iteration with built-in pagination using a First and Next method

    Obviously the most convenient is a slice of all the objects. This is possible for all collections that are not paginated. For paginated collections, the current First, Next idiom, e.g.

    c := NewCollection(...)
    for v, err := c.First(); v != nil; v, err = c.Next() {
        if err != nil {
            // handle err and break
        }
        // do something with v
    }
    

    is convenient because it handles pagination under the hood and allows for clean iteration over every object. It has a few problems though:

    1. A user has no control over pagination (and therefore the number of API requests they make)
    2. If First returns a nil pointer to an object, and an error, say a critical error, the error isn't caught. Sure you could declare err before the loop and check it after the loop, but that's a terrible idea.
    3. Much of the API returns objects not pointers, where this iteration API requires pointers because it uses nil as the loop terminator.

    The thin wrapper with manual pagination is simple. It'd be nice to have some optional API on top it to allow for iteration, perhaps using a channel (since they are iterable using range).

  • Endpoint documentation should contain links to API documentation

    Endpoint documentation should contain links to API documentation

    Each method's comment block should contain a link to the endpoint's corresponding documentation on the BreweryDB website. This makes it easier for users to see how to use the endpoint and help keep the library in sync with the actual web API.

  • HTTP error codes are swallowed

    HTTP error codes are swallowed

    As of now, if there is an HTTP error during a request, the error code is caught and swallowed and a very useless message is returned in its place.

    Google's Github Go API actually returns an entire Response object for each endpoint, along with the result "object" and an error. This makes sense, but I don't know that it's not overkill. Regardless, something must be done.

  • "Extra" JSON fields are lost

    In the case that there are JSON fields in a response that aren't defined in the corresponding Go struct, it would be nice if they were unmarshalled into some extra space. Apparently other JSON libraries are capable of doing this. At the very least it would help develop/debug this library as there are a few discrepancies in the BreweryDB API documentation.

  • "Search" endpoint can't search all types of data

    The "search" endpoint on BreweryDB allows for searching breweries, beers, guilds and events but since objects of each type are returned in one JSON response, the Go implementation just has 4 separate methods for searching each type. This makes the code simple, but it also means a user must make more requests to search for multiple types of objects, e.g. searching for both breweries and beers with a specific term requires two method calls and two HTTP requests.

  • Some services only have one or two methods

    Some services only have one or two methods

    Some services have only one or two methods, e.g. Heartbeat.Heartbeat. The "Service" is probably unnecessary and the Heartbeat method could just move to the Client.

API-HTTP service for wav-file synthesis based on sound library (morphemes)

Сервис для генерации аудио-файлов по заданной последовательности звуков из библиотеки. Предоставляет HTTP-API для передачи последовательности для гене

Jan 9, 2022
Go-http-client: An enhanced http client for Golang
Go-http-client: An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Jan 7, 2023
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple Weather API Simple weather api app created using golang and Open Weather

Feb 6, 2022
go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface

go-whatsapp-rest-API go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface Multi-devices (MD) Support. This ver

Dec 15, 2022
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)

Gosip - SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang) Main features Unattended authentication using different strategies

Jan 2, 2023
Go client for wit.ai HTTP API
Go client for wit.ai HTTP API

This repository is community-maintained. We gladly accept pull requests. Please see the Wit HTTP Reference for all supported endpoints. Go client for

Jan 7, 2023
Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.

YNAB API Go Library This is an UNOFFICIAL Go client for the YNAB API. It covers 100% of the resources made available by the YNAB API. Installation go

Oct 6, 2022
An API client for the Notion API implemented in Golang

An API client for the Notion API implemented in Golang

Dec 30, 2022
lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin to AWS Lambda and Amazon API Gateway.

aws-lambda-go-api-proxy makes it easy to run Golang APIs written with frameworks such as Gin with AWS Lambda and Amazon API Gateway.

Jan 6, 2023
A API scanner written in GOLANG to scan files recursively and look for API keys and IDs.

GO FIND APIS _____ ____ ______ _____ _ _ _____ _____ _____ _____ / ____|/ __ \ | ____|_ _| \ | | __ \ /\ | __ \_

Oct 25, 2021
The NVD API is an unofficial Go wrapper around the NVD API.

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Jan 7, 2023
A Wrapper Client for Google Spreadsheet API (Sheets API)

Senmai A Wrapper Client for Google Spreadsheet API (Sheets API) PREPARATION Service Account and Key File Create a service account on Google Cloud Plat

Nov 5, 2021
💾 Wolke API is the API behind Wolke image storage and processing aswell as user management

?? Wolke API Wolke API is the API behind Wolke image storage and processing aswell as user management Deploying To deploy Wolke Bot you'll need podman

Dec 21, 2021
Upcoming mobiles api (UpMob API)

upcoming_mobiles_api (UpMob API) UpMob API scraps 91mobiles.com to get devices i

Dec 21, 2021
Arweave-api - Arweave API implementation in golang

Arweave API Go implementation of the Arweave API Todo A list of endpoints that a

Jan 16, 2022
Api-product - A basic REST-ish API that allows you to perform CRUD operations for Products

Description A basic REST-ish API that allows you to perform CRUD operations for

Jan 3, 2022
Contact-api - API for websites I have designed that have to send unauthenticated email

contact https://aws.amazon.com/premiumsupport/knowledge-center/custom-headers-ap

Apr 11, 2022
Triangula-api-server - API server for processing images with Triangula

Triangula API server Minimalistic API server that calculates and serves artistic

Jan 10, 2022
Reservationbox-api - Reservationbox Api with golang
Reservationbox-api - Reservationbox Api with golang

reservationbox-api How to set up application Cloning git on this link : https://

Jan 30, 2022