govinfo

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package govinfo is the library behind the govinfo command line: the HTTP client, request shaping, and the typed data models for the US Government Publishing Office GovInfo API (api.govinfo.gov).

The GovInfo API is open for public data with DEMO_KEY: no signup required. This package wraps the REST API with a rate-limited client that the kit operations consume.

Index

Constants

View Source
const DefaultUserAgent = "govinfo-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to the GovInfo API honestly.

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

Host is the canonical site hostname used in URI routing.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a rate-limited HTTP client for the GovInfo REST API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) GetPackage

func (c *Client) GetPackage(ctx context.Context, packageID string) (*PackageSummary, error)

GetPackage fetches the summary for a single package by ID.

func (*Client) ListCollections

func (c *Client) ListCollections(ctx context.Context) ([]Collection, error)

ListCollections fetches all document collections from GovInfo.

func (*Client) ListPackages

func (c *Client) ListPackages(ctx context.Context, collection, since string, size, page int) ([]Package, error)

ListPackages fetches packages from a collection since a given date. collection: e.g. "BILLS" since: RFC3339 or date string, e.g. "2020-01-01T00:00:00Z" size: page size (default 25) page: 1-based page number (maps to offsetMark via cursor, simplified here)

type Collection

type Collection struct {
	Code         string `json:"code"`
	Name         string `json:"name"`
	PackageCount int    `json:"packageCount"`
}

Collection is a document collection available in GovInfo.

type Config

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

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for api.govinfo.gov.

type Domain

type Domain struct{}

Domain is the GovInfo 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 any accepted input into the canonical (uriType, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme and the identity the single-site binary inherits.

func (Domain) Locate

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

Locate returns the canonical URL for a (uriType, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Package

type Package struct {
	PackageID    string `json:"packageId" kit:"id"`
	Congress     string `json:"congress"`
	DocClass     string `json:"docClass"`
	Title        string `json:"title"`
	DateIssued   string `json:"dateIssued"`
	LastModified string `json:"lastModified"`
}

Package is a document package within a collection.

type PackageSummary

type PackageSummary struct {
	PackageID    string `json:"packageId" kit:"id"`
	Title        string `json:"title"`
	DocClass     string `json:"docClass"`
	Congress     string `json:"congress"`
	Session      string `json:"session"`
	DateIssued   string `json:"dateIssued"`
	LastModified string `json:"lastModified"`
	DownloadURL  string `json:"downloadURL"`
}

PackageSummary is the detailed metadata for a single package.

Jump to

Keyboard shortcuts

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