usgsquake

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 usgsquake 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/usgsquake-cli/usgsquake"

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

Package usgsquake is the library behind the quake 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) Count

func (c *Client) Count(ctx context.Context, p CountParams) (*Count, error)

Count queries /count for the number of earthquakes matching params.

func (*Client) Get

func (c *Client) Get(ctx context.Context, eventID string) (*Earthquake, error)

Get fetches a single earthquake event by USGS event ID.

func (*Client) List

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

List queries /query for earthquakes matching the given params.

func (*Client) Nearby

func (c *Client) Nearby(ctx context.Context, lat, lon, radiusKm, minMag float64, limit int) ([]Earthquake, error)

Nearby queries /query for earthquakes near a point.

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 Count

type Count struct {
	Count int `json:"count"`
}

Count is the result of a /count query.

type CountParams

type CountParams struct {
	MinMag float64
	Start  string
	End    string
}

CountParams holds filters for a count query.

type Domain

type Domain struct{}

Domain is the usgsquake 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 {
	ID           string  `json:"id"`
	Place        string  `json:"place"`
	Title        string  `json:"title"`
	Status       string  `json:"status"`
	Type         string  `json:"type"`
	Magnitude    float64 `json:"magnitude"`
	Time         int64   `json:"time"`    // Unix milliseconds
	Updated      int64   `json:"updated"` // Unix milliseconds
	Lat          float64 `json:"lat"`
	Lon          float64 `json:"lon"`
	Depth        float64 `json:"depth_km"`
	Tsunami      int     `json:"tsunami"`
	Significance int     `json:"significance"`
	URL          string  `json:"url"`
}

Earthquake is one seismic event from the USGS catalog.

type ListParams

type ListParams struct {
	MinMag float64
	MaxMag float64
	Start  string
	End    string
	Limit  int
}

ListParams holds optional filters for a list query.

Jump to

Keyboard shortcuts

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