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
- type Brewery
- type Client
- func (c *Client) Get(ctx context.Context, id string) (*Brewery, error)
- func (c *Client) GetMeta(ctx context.Context) (*Meta, error)
- func (c *Client) List(ctx context.Context, opts ListOptions) ([]Brewery, error)
- func (c *Client) Random(ctx context.Context, size int) ([]Brewery, error)
- func (c *Client) Search(ctx context.Context, query string, limit int) ([]Brewery, error)
- type Config
- type Domain
- type ListOptions
- type Meta
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
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
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 (*Client) Get ¶ added in v0.1.1
Get returns a single brewery by its UUID. Returns an error for unknown IDs.
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) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, hostnames, and the identity used in help and version.