usgs

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 usgs exposes the USGS Earthquake catalog as a kit Domain driver.

A multi-domain host (ant) enables it with a single blank import:

import _ "github.com/tamnd/usgs-cli/usgs"

The same Domain also builds the standalone usgs binary (see cli.NewApp).

Package usgs is the library behind the usgs command line: the HTTP client, request shaping, and typed data models for the USGS FDSNWS Earthquake Event Web Service (earthquake.usgs.gov/fdsnws/event/1).

The USGS API is free and requires no API key. It returns seismic events worldwide in GeoJSON format with magnitude, location, depth, and metadata.

Index

Constants

View Source
const Host = "earthquake.usgs.gov"

Host is the API host this client talks to.

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 USGS earthquake API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Query

func (c *Client) Query(ctx context.Context, p QueryParams) ([]Earthquake, error)

Query calls /fdsnws/event/1/query and returns a slice of Earthquake records.

func (*Client) Recent

func (c *Client) Recent(ctx context.Context) ([]Earthquake, error)

Recent returns significant earthquakes from the last 30 days (mag >= 6).

type Config

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

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the usgs driver.

func (Domain) Classify

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

Classify turns any input into the canonical (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(t, id string) (string, error)

Locate returns the live USGS 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 Earthquake

type Earthquake struct {
	Place     string `kit:"id" json:"place"`
	Magnitude string `json:"magnitude"` // "%.1f"
	Time      string `json:"time"`      // RFC3339 UTC
	Depth     string `json:"depth_km"`  // "%.1f"
	Latitude  string `json:"latitude"`  // "%.4f"
	Longitude string `json:"longitude"` // "%.4f"
	Type      string `json:"type"`
}

Earthquake is one seismic event from the USGS catalog, with all numeric fields pre-formatted as strings for clean JSON/tabular output.

type QueryParams

type QueryParams struct {
	Start   string
	End     string
	MinMag  string
	MaxMag  string
	Limit   int
	OrderBy string
}

QueryParams holds optional filters for a query.

Jump to

Keyboard shortcuts

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