bls

package
v0.1.0 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 bls is the library behind the bls command line: the HTTP client, request shaping, and the typed data models for the Bureau of Labor Statistics (BLS) Public Data API.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.

Index

Constants

View Source
const Host = "api.bls.gov"

Host is the canonical BLS API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the BLS Public Data API over HTTPS.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured by cfg.

func (*Client) MultiSeries

func (c *Client) MultiSeries(ctx context.Context, seriesIDs []string, opts SeriesOptions) ([]*SeriesData, error)

MultiSeries fetches data for multiple series IDs via POST /timeseries/data/.

func (*Client) Series

func (c *Client) Series(ctx context.Context, seriesID string, opts SeriesOptions) (*SeriesData, error)

Series fetches data for a single series via GET /timeseries/data/{seriesId}.

type Config

type Config struct {
	BaseURL         string
	UserAgent       string
	RegistrationKey string // optional; empty = anonymous tier
	Rate            time.Duration
	Timeout         time.Duration
	Retries         int
}

Config holds all tunable settings for the BLS client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the BLS public API.

type DataPoint

type DataPoint struct {
	Year       string     `json:"year"`
	Period     string     `json:"period"` // M01–M12, Q01–Q04, A01
	PeriodName string     `json:"period_name"`
	Value      string     `json:"value"`
	Footnotes  []Footnote `json:"footnotes,omitempty"`
}

DataPoint is one observation in a series.

type Domain

type Domain struct{}

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

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

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

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

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

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Footnote

type Footnote struct {
	Code string `json:"code"`
	Text string `json:"text,omitempty"`
}

Footnote is an annotation attached to a data point.

type SeriesData

type SeriesData struct {
	SeriesID string      `json:"series_id" kit:"id"`
	Data     []DataPoint `json:"data"`
}

SeriesData is the outer wrapper for one time series response.

type SeriesOptions

type SeriesOptions struct {
	StartYear string // e.g. "2022"; empty = BLS default (last 3 years)
	EndYear   string // e.g. "2023"; empty = BLS default
	Latest    bool   // if true, return only the first (most recent) data point
	Limit     int    // max data points to return; 0 = all
}

SeriesOptions controls filtering for Series and MultiSeries calls.

Jump to

Keyboard shortcuts

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