wttr

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 wttr is the library behind the wttr command line: the HTTP client, request shaping, and the typed data models for the wttr.in API (weather for any city, no key required).

The Client 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 Host = "wttr.in"

Host is the site 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 wttr.in over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured from cfg.

func (*Client) Current

func (c *Client) Current(ctx context.Context, city string) (*Weather, error)

Current fetches the current weather for the given city.

type Config

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

Config holds all tuneable parameters for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the production configuration for wttr.in.

type Domain

type Domain struct{}

Domain is the wttr driver.

func (Domain) Classify

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

Classify turns a city name or wttr.in URL 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(uriType, id string) (string, error)

Locate returns 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 Weather

type Weather struct {
	City        string `json:"city"`
	TempC       string `json:"temp_c"`
	TempF       string `json:"temp_f"`
	FeelsLikeC  string `json:"feels_like_c"`
	Description string `json:"description"`
	WindSpeed   string `json:"wind_speed_kmph"`
	Humidity    string `json:"humidity"`
	Visibility  string `json:"visibility"`
	Pressure    string `json:"pressure"`
	UV          string `json:"uv_index"`
	MaxTempC    string `json:"max_temp_c"`
	MinTempC    string `json:"min_temp_c"`
	Date        string `json:"date"`
	Country     string `json:"country"`
	Region      string `json:"region"`
}

Weather holds the current conditions and today's forecast for one city.

Jump to

Keyboard shortcuts

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