metno

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 metno exposes the MET Norway weather API as a kit Domain driver. A multi-domain host (ant) enables it with a single blank import:

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

The same Domain also builds the standalone metno binary, so the binary and a host share one source of truth.

Package metno is the library behind the metno command line: the HTTP client, request shaping, and typed data models for the Norwegian Meteorological Institute weather API (api.met.no).

Usage policy: every request MUST carry a meaningful User-Agent header identifying the application and a contact email. The API blocks requests without a proper User-Agent. A rate of 1 req/s is polite and appropriate.

Index

Constants

View Source
const Host = "api.met.no"

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 api.met.no over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Forecast

func (c *Client) Forecast(ctx context.Context, lat, lon float64, limit int) ([]WeatherPoint, error)

Forecast fetches the compact location forecast for the given lat/lon and returns up to limit time-steps. If limit <= 0 all steps are returned.

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 sensible defaults: 1 req/s rate limit, 30s timeout, 3 retries, and the required User-Agent identifying this tool and contact.

type Domain

type Domain struct{}

Domain is the metno driver. It carries no state; the per-run client is built by the factory Register hands to kit.

func (Domain) Classify

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

Classify turns an input into the canonical (type, id). A "lat,lon" pair (two floats separated by comma) is a "location"; everything else is a "query".

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). For "location" the id is "lat,lon"; Locate returns the yr.no forecast URL.

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type WeatherPoint

type WeatherPoint struct {
	Time        string  `kit:"id" json:"time"`
	Temperature float64 `json:"temperature"`
	WindSpeed   float64 `json:"wind_speed"`
	WindDir     float64 `json:"wind_direction"`
	Humidity    float64 `json:"humidity"`
	CloudCover  float64 `json:"cloud_cover"`
	Symbol      string  `json:"symbol"`    // from next_1_hours or next_6_hours
	Precip1h    float64 `json:"precip_1h"` // 0 if not available
}

WeatherPoint is one time-step of a location forecast.

Jump to

Keyboard shortcuts

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