dailymed

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: 10 Imported by: 0

Documentation

Overview

Package dailymed is the library behind the dailymed command line: the HTTP client, request shaping, and the typed data models for DailyMed.

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 API throws under load.

Index

Constants

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

BaseURL is the root every request is built from.

View Source
const DefaultRate = 300 * time.Millisecond

DefaultRate is the minimum gap between requests.

View Source
const DefaultRetries = 3

DefaultRetries is the number of retry attempts on transient errors.

View Source
const DefaultTimeout = 15 * time.Second

DefaultTimeout is the per-request HTTP timeout.

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

DefaultUserAgent identifies the client to DailyMed in a transparent, polite way.

View Source
const Host = "dailymed.nlm.nih.gov"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the DailyMed public API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with the sensible defaults.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches a URL and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetSPL

func (c *Client) GetSPL(ctx context.Context, setid string) (*SPL, error)

GetSPL fetches a single SPL record by its setid (UUID string). It uses the packaging.json sub-endpoint which returns full SPL metadata.

func (*Client) ListNDCs

func (c *Client) ListNDCs(ctx context.Context, setid string, limit int) ([]NDC, error)

ListNDCs returns the NDC codes for the SPL identified by setid. limit caps the result slice; zero means no cap.

func (*Client) SearchSPLs

func (c *Client) SearchSPLs(ctx context.Context, query string, limit, page int) ([]SPL, error)

SearchSPLs searches DailyMed drug labels by drug name. limit is the page size, page is 1-based.

type Domain

type Domain struct{}

Domain is the DailyMed 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 setid or full DailyMed 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 page 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 NDC

type NDC struct {
	NDC string `kit:"id" json:"ndc"`
}

NDC represents a National Drug Code record associated with an SPL.

type SPL

type SPL struct {
	SetID         string `kit:"id" json:"setid"`
	Title         string `json:"title"`
	PublishedDate string `json:"published_date"`
}

SPL represents a single Structured Product Label (drug label) record.

Jump to

Keyboard shortcuts

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