openbrewery

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package openbrewery is the library behind the openbrewery command line: the HTTP client, request shaping, and typed data models for the Open Brewery DB.

The Client sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx) with exponential backoff. Four operations are provided: list breweries with filters, full-text search, random, and database statistics.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const Host = "api.openbrewerydb.org"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brewery

type Brewery struct {
	ID      string `kit:"id" json:"id"`
	Name    string `json:"name"`
	Type    string `json:"type"` // brewery_type in API
	City    string `json:"city"`
	State   string `json:"state"` // state_province in API
	Country string `json:"country"`
	Address string `json:"address"` // address_1 in API
	Phone   string `json:"phone"`
	Website string `json:"website"` // website_url in API
	Lat     string `json:"lat"`     // latitude in API (may be number or string)
	Lon     string `json:"lon"`     // longitude in API (may be number or string)
}

Brewery is a brewery from the Open Brewery DB. JSON tags use the clean output names; the raw API field names are handled by UnmarshalJSON.

func (*Brewery) UnmarshalJSON added in v0.1.1

func (b *Brewery) UnmarshalJSON(data []byte) error

UnmarshalJSON maps API wire fields to clean Brewery fields.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Open Brewery DB over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Get added in v0.1.1

func (c *Client) Get(ctx context.Context, id string) (*Brewery, error)

Get returns a single brewery by its UUID. Returns an error for unknown IDs.

func (*Client) GetMeta

func (c *Client) GetMeta(ctx context.Context) (*Meta, error)

GetMeta returns database statistics from the /meta endpoint.

func (*Client) List

func (c *Client) List(ctx context.Context, opts ListOptions) ([]Brewery, error)

List returns breweries with optional filters. Paginates automatically.

func (*Client) Random

func (c *Client) Random(ctx context.Context, size int) ([]Brewery, error)

Random returns size random breweries. size defaults to 1 if <= 0.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, limit int) ([]Brewery, error)

Search returns breweries matching the query string.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds tunable knobs for the HTTP client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for production use.

type Domain

type Domain struct{}

Domain is the openbrewery kit driver. It carries no state; the per-run client is built by the factory Register hands to kit.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns a brewery ID or URL into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and the identity used in help and version.

func (Domain) Locate

func (Domain) Locate(t, id string) (string, error)

Locate returns the live API URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and all operations onto app.

type ListOptions

type ListOptions struct {
	City    string // by_city
	State   string // by_state
	Country string // by_country
	Type    string // by_type
	Limit   int    // max results; 0 = default 50
}

ListOptions controls filtering for the List method.

type Meta

type Meta struct {
	Total     int            `json:"total"`
	ByType    map[string]int `json:"by_type"`
	ByState   map[string]int `json:"by_state"`
	ByCountry map[string]int `json:"by_country"`
}

Meta holds database-level statistics from the /v1/breweries/meta endpoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL