meteomatics

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 12 Imported by: 0

README

PkgGoDev Coverage Status

logo

GO connector to the Meteomatics Weather API

Key features

  • Idomatic Go API.
  • Support for CSV, JSON, and PNG requests.
  • Support for GET and POST requests.
  • Support for Basic and Bearer auth.
  • Support for all location types.
  • Support for all parameters.
  • Support for all time types.
  • Support for context.
  • Support for Go modules.
  • Well tested.

Example

func ExampleNewClient_simple() {
	client := meteomatics.NewClient(
		meteomatics.WithBasicAuth(
			os.Getenv("METEOMATICS_USERNAME"),
			os.Getenv("METEOMATICS_PASSWORD"),
		),
	)

	cr, err := client.RequestCSV(
		context.Background(),
		meteomatics.TimeSlice{
			meteomatics.TimeNow,
			meteomatics.NowOffset(1 * time.Hour),
		},
		meteomatics.Parameter{
			Name:  meteomatics.ParameterTemperature,
			Level: meteomatics.LevelMeters(2),
			Units: meteomatics.UnitsCelsius,
		},
		meteomatics.Postal{
			CountryCode: "CH",
			ZIPCode:     "9000",
		},
		&meteomatics.RequestOptions{},
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(cr.Parameters)
	for _, row := range cr.Rows {
		fmt.Println(row.ValidDate)
		fmt.Println(row.Values)
	}
}

License

MIT

Documentation

Overview

Package meteomatics is a client library for the Meteomatics API. See https://www.meteomatics.com/en/api/overview/.

Index

Constants

View Source
const DefaultBaseURL = "https://api.meteomatics.com"

DefaultBaseURL is the default base URL.

Variables

View Source
var (
	FormatGrads = Format{
				// contains filtered or unexported fields
	}
	FormatCSV = Format{
				// contains filtered or unexported fields
	}
	FormatHTML = Format{
				// contains filtered or unexported fields
	}
	FormatHTMLMap = Format{
					// contains filtered or unexported fields
	}
	FormatJSON = Format{
				// contains filtered or unexported fields
	}
	FormatNetCDF = Format{
					// contains filtered or unexported fields
	}
	FormatPNG = Format{
				// contains filtered or unexported fields
	}
	FormatPNGDefault = Format{
						// contains filtered or unexported fields
	}
	FormatPNGJet = Format{
					// contains filtered or unexported fields
	}
	FormatPNGJetSegmented = Format{
							// contains filtered or unexported fields
	}
	FormatPNGBlueToRed = Format{
						// contains filtered or unexported fields
	}
	FormatPNGBlueMagenta = Format{
							// contains filtered or unexported fields
	}
	FormatPNGBlues = Format{
					// contains filtered or unexported fields
	}
	FormatPNGGray = Format{
					// contains filtered or unexported fields
	}
	FormatPNGPeriodic = Format{
						// contains filtered or unexported fields
	}
	FormatPNGPlasma = Format{
					// contains filtered or unexported fields
	}
	FormatPNGPrism = Format{
					// contains filtered or unexported fields
	}
	FormatPNGReds = Format{
					// contains filtered or unexported fields
	}
	FormatPNGSeismic = Format{
						// contains filtered or unexported fields
	}
	FormatXML = Format{
				// contains filtered or unexported fields
	}
)

Formats.

Functions

This section is empty.

Types

type CSVRegionResponse

type CSVRegionResponse struct {
	ValidDate time.Time
	Parameter ParameterString
	Lats      []float64
	Lons      []float64
	Values    [][]float64
}

A CSVRegionResponse is a response to a CSV region request.

type CSVResponse

type CSVResponse struct {
	Parameters []ParameterString
	Rows       []CSVRow
}

A CSVResponse is a response to a CSV request.

type CSVRouteResponse

type CSVRouteResponse struct {
	Parameters []ParameterString
	Rows       []CSVRouteRow
}

A CSVRouteResponse is a response to a CSV route request.

type CSVRouteRow

type CSVRouteRow struct {
	Lat       float64
	Lon       float64
	ValidDate time.Time
	Values    []float64
}

A CSVRouteRow is a CSV route row.

type CSVRow

type CSVRow struct {
	ValidDate time.Time
	Values    []float64
}

A CSVRow is a CSV row.

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a Client.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient returns a new Client with options set.

func (*Client) Request

Request performs a raw request. It is the caller's responsibility to interpret the []byte returned.

func (*Client) RequestCSV

RequestCSV requests a forecast in CSV format.

func (*Client) RequestCSVRegion

func (c *Client) RequestCSVRegion(ctx context.Context, ts TimeStringer, ps ParameterStringer, ls LocationStringer, options *RequestOptions) (*CSVRegionResponse, error)

RequestCSVRegion requests a region forecast in CSV format.

func (*Client) RequestCSVRoute

func (c *Client) RequestCSVRoute(ctx context.Context, ts TimeStringer, ps ParameterStringer, ls LocationStringer, options *RequestOptions) (*CSVRouteResponse, error)

RequestCSVRoute requests a region forecast in CSV format.

func (*Client) RequestJSON

RequestJSON requests a forecast in JSON format.

func (*Client) RequestJSONRoute

func (c *Client) RequestJSONRoute(ctx context.Context, ts TimeStringer, ps ParameterStringer, ls LocationStringer, options *RequestOptions) (*JSONRouteResponse, error)

RequestJSONRoute requests a forecast in JSON format.

type ClientOption

type ClientOption func(*Client)

A ClientOption sets an option on a Client.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the base URL.

func WithBasicAuth

func WithBasicAuth(username, password string) ClientOption

WithBasicAuth sets the username and password for basic authentication.

func WithBearerAuth

func WithBearerAuth(token string) ClientOption

WithBearerAuth adds bearer token header

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets the http.Client.

func WithTransportMethod

func WithTransportMethod(method TransportMethod) ClientOption

type Error

type Error struct {
	Request      *http.Request
	Response     *http.Response
	ResponseBody []byte
}

An Error is an error.

func (*Error) Error

func (e *Error) Error() string

type Format

type Format struct {
	// contains filtered or unexported fields
}

A Format is a format.

func (Format) ContentType

func (f Format) ContentType() string

ContentType returns f's content type.

func (Format) FormatString

func (f Format) FormatString() FormatString

FormatString returns f as a FormatString.

type FormatString

type FormatString string

A FormatString is a string that represents a format.

type FormatStringer

type FormatStringer interface {
	ContentType() string
	FormatString() FormatString
}

A FormatStringer is something that can behave as a format.

type Interval

type Interval time.Duration

An Interval is a time.Duration.

func (Interval) IntervalString

func (i Interval) IntervalString() IntervalString

IntervalString returns i as an IntervalString.

type IntervalString

type IntervalString string

An IntervalString is a string representation of an interval.

const (
	Interval5Min  IntervalString = "5min"
	Interval10Min IntervalString = "10min"
	Interval15Min IntervalString = "15min"
	Interval30Min IntervalString = "30min"
	Interval1H    IntervalString = "1h"
	Interval3H    IntervalString = "3h"
	Interval6H    IntervalString = "6h"
	Interval12H   IntervalString = "12h"
	Interval24H   IntervalString = "24h"
)

Intervals.

func (IntervalString) IntervalString

func (s IntervalString) IntervalString() IntervalString

IntervalString returns s as an IntervalString.

type IntervalStringer

type IntervalStringer interface {
	IntervalString() IntervalString
}

An IntervalStringer can be converted to an IntervalString.

type JSONCoordinates

type JSONCoordinates struct {
	Dates     []JSONDate `json:"dates"`
	Lat       float64    `json:"lat"`
	Lon       float64    `json:"lon"`
	StationID string     `json:"station_id"`
}

A JSONCoordinates is a series of values.

type JSONData

type JSONData struct {
	Coordinates []JSONCoordinates `json:"coordinates"`
	Parameter   ParameterString   `json:"parameter"`
}

A JSONData is a parameter measured at a coordinate.

type JSONDate

type JSONDate struct {
	Date  time.Time `json:"date"`
	Value float64   `json:"value"`
}

A JSONDate is a value at a date.

type JSONResponse

type JSONResponse struct {
	Version       string     `json:"version"`
	User          string     `json:"user"`
	DateGenerated time.Time  `json:"dateGenerated"`
	Status        string     `json:"status"`
	Data          []JSONData `json:"data"`
}

A JSONResponse is a JSON response.

func (*JSONResponse) Error

func (r *JSONResponse) Error() string

type JSONRouteData

type JSONRouteData struct {
	Lat        float64              `json:"lat"`
	Lon        float64              `json:"lon"`
	Date       time.Time            `json:"date"`
	Parameters []JSONRouteParameter `json:"parameters"`
}

A JSONRouteData is a JSON route data.

type JSONRouteParameter

type JSONRouteParameter struct {
	Parameter ParameterString `json:"parameter"`
	Value     float64         `json:"value"`
}

A JSONRouteParameter is a JSON route parameter.

type JSONRouteResponse

type JSONRouteResponse struct {
	Version       string          `json:"version"`
	User          string          `json:"user"`
	DateGenerated time.Time       `json:"dateGenerated"`
	Status        string          `json:"status"`
	Data          []JSONRouteData `json:"data"`
}

A JSONRouteResponse is a response to a JSON route request.

func (*JSONRouteResponse) Error

func (r *JSONRouteResponse) Error() string

type LevelCentimeters

type LevelCentimeters int

A LevelCentimeters is level in centimeters.

func (LevelCentimeters) LevelString

func (l LevelCentimeters) LevelString() LevelString

LevelString returns l as a LevelString.

type LevelHectopascals

type LevelHectopascals int

A LevelHectopascals is level in hectopascals.

func (LevelHectopascals) LevelString

func (l LevelHectopascals) LevelString() LevelString

LevelString returns l as a LevelString.

type LevelMeters

type LevelMeters int

A LevelMeters is level in meters.

func (LevelMeters) LevelString

func (l LevelMeters) LevelString() LevelString

LevelString returns l as a LevelString.

type LevelString

type LevelString string

A LevelString is a string representation of a level.

type LevelStringer

type LevelStringer interface {
	LevelString() LevelString
}

A LevelStringer can be converted to a LevelString.

type Line

type Line struct {
	Start Point
	End   Point
	N     int
}

A Line is a line.

func (Line) LocationString

func (l Line) LocationString() LocationString

LocationString returns l as a LocationString.

type LocationSlice

type LocationSlice []LocationStringer

A LocationSlice is a slice of LocationStringers.

func (LocationSlice) LocationString

func (s LocationSlice) LocationString() LocationString

LocationString returns s as a LocationString.

type LocationString

type LocationString string

A LocationString is a string representing a location.

const (
	LocationWorld        LocationString = "world"
	LocationGlobal       LocationString = "global"
	LocationAfrica       LocationString = "africa"
	LocationAsia         LocationString = "asia"
	LocationAustralia    LocationString = "australia"
	LocationEurope       LocationString = "europe"
	LocationNorthAmerica LocationString = "north-america"
	LocationSouthAmerica LocationString = "south-america"
)

Location shortcuts.

func (LocationString) LocationString

func (s LocationString) LocationString() LocationString

LocationString returns s as a LocationString.

type LocationStringer

type LocationStringer interface {
	LocationString() LocationString
}

A LocationStringer can be converted to a LocationString.

type NowOffset

type NowOffset time.Duration

A NowOffset is a time relative to now.

func (NowOffset) TimeString

func (o NowOffset) TimeString() TimeString

TimeString returns o as a TimeString.

type Parameter

type Parameter struct {
	Name     ParameterName
	Level    LevelStringer
	Interval IntervalStringer
	Units    Units
}

A Parameter is a parameter.

func (Parameter) ParameterString

func (p Parameter) ParameterString() ParameterString

ParameterString returns p as a ParameterString.

type ParameterName

type ParameterName string

A ParameterName is a parameter name.

const (
	ParameterTemperature              ParameterName = "t"
	ParameterTemperatureMean          ParameterName = "t_mean"
	ParameterTemperatureMin           ParameterName = "t_min"
	ParameterTemperatureMax           ParameterName = "t_max"
	ParameterRelativeHumidity         ParameterName = "relative_humidity"
	ParameterAbsoluteHumidity         ParameterName = "absolute_humidity"
	ParameterDewPoint                 ParameterName = "dew_point"
	ParameterPressureMSL              ParameterName = "msl_pressure"
	ParameterPressureSurface          ParameterName = "sfc_pressure"
	ParameterPressure                 ParameterName = "pressure"
	ParameterAirDensity               ParameterName = "air_density"
	ParameterWindSpeed                ParameterName = "wind_speed"
	ParameterWindDirection            ParameterName = "wind_direction"
	ParameterWindSpeedU               ParameterName = "wind_speed_u"
	ParameterWindSpeedV               ParameterName = "wind_speed_v"
	ParameterWindGusts                ParameterName = "wind_gusts"
	ParameterCloudCoverLow            ParameterName = "low_cloud_cover"
	ParameterCloudCoverMedium         ParameterName = "medium_cloud_cover"
	ParameterCloudCoverHigh           ParameterName = "high_cloud_cover"
	ParameterCloudCoverTotal          ParameterName = "total_cloud_cover"
	ParameterCloudCoverEffective      ParameterName = "effective_cloud_cover"
	ParameterPrecipitation            ParameterName = "precip"
	ParameterPrecipitationType        ParameterName = "precip_type"
	ParameterPrecipitationProbability ParameterName = "prob_precip"
	ParameterHail                     ParameterName = "hail"
	ParameterEvaporation              ParameterName = "evaporation"
	ParameterCAPE                     ParameterName = "cape"
	ParameterLiftedIndex              ParameterName = "lifted_index"
	ParameterThunderstormProbablility ParameterName = "prob_tstorm"
	ParameterFrostDepth               ParameterName = "frost_depth"
	ParameterSnowMelt                 ParameterName = "snow_melt"
	ParameterSnowDepth                ParameterName = "snow_depth"
	ParameterSnowLine                 ParameterName = "snow_line"
	ParameterFreezingLevel            ParameterName = "freezing_level"
	ParameterFreezingLevelAGL         ParameterName = "freezing_level_agl"
	ParameterGeopotentialHeight       ParameterName = "geopotential_height"
	ParameterRadiationClearSky        ParameterName = "clear_sky_rad"
	ParameterEnergyClearSky           ParameterName = "clear_sky_energy"
	ParameterRadiationDiffuse         ParameterName = "diffuse_rad"
	ParameterRadiationDirect          ParameterName = "direct_rad"
	ParameterRadiationGlobal          ParameterName = "global_rad"
	ParameterPolarVortex              ParameterName = "polar_vortex"
)

Parameter names.

type ParameterSlice

type ParameterSlice []ParameterStringer

A ParameterSlice is a slice of ParameterStringers.

func (ParameterSlice) ParameterString

func (s ParameterSlice) ParameterString() ParameterString

ParameterString returns s as a ParameterString.

type ParameterString

type ParameterString string

A ParameterString is a string representing a parameter.

func (ParameterString) ParameterString

func (s ParameterString) ParameterString() ParameterString

ParameterString returns s as a ParameterString.

type ParameterStringer

type ParameterStringer interface {
	ParameterString() ParameterString
}

A ParameterStringer can be converted to a ParameterString.

type Point

type Point struct {
	Lat float64
	Lon float64
}

A Point is a point.

func (Point) LocationString

func (p Point) LocationString() LocationString

LocationString returns p as a LocationString.

type PointList

type PointList []Point

A PointList is a list of Points.

func (PointList) LocationString

func (l PointList) LocationString() LocationString

LocationString returns l as a LocationString.

type Polyline

type Polyline struct {
	Start    Point
	Segments []PolylineSegment
}

A Polyline is a polyline.

func (Polyline) LocationString

func (p Polyline) LocationString() LocationString

LocationString returns p as a LocationString.

type PolylineSegment

type PolylineSegment struct {
	End Point
	N   int
}

A PolylineSegment is a segment of a Polyline.

type Postal

type Postal struct {
	CountryCode string
	ZIPCode     string
}

A Postal is a country code and a ZIP code.

func (Postal) LocationString

func (p Postal) LocationString() LocationString

LocationString returns p as a LocationString.

type PrecipType

type PrecipType int

PrecipType is a type of precipitation.

const (
	PrecipNone             PrecipType = 0
	PrecipRain             PrecipType = 1
	PrecipRainAndSnowMixed PrecipType = 2
	PrecipSnow             PrecipType = 3
	PrecipSleet            PrecipType = 4
	PrecipFreezingRain     PrecipType = 5
)

Precipitation types.

type RectangleN

type RectangleN struct {
	Min  Point
	Max  Point
	NLon int
	NLat int
}

A RectangleN is a rectangle with a number of points.

func (RectangleN) LocationString

func (r RectangleN) LocationString() LocationString

LocationString returns r as a LocationString.

type RectangleRes

type RectangleRes struct {
	Min    Point
	Max    Point
	ResLat float64
	ResLon float64
}

A RectangleRes is a rectangle with a resolution.

func (RectangleRes) LocationString

func (r RectangleRes) LocationString() LocationString

LocationString returns r as a LocationString.

type RequestOptions

type RequestOptions struct {
	Source                string
	TemporalInterpolation string
	EnsembleSelect        string
	ClusterSelect         string
	Timeout               int
	Route                 bool
}

RequestOptions are per-request options.

func (*RequestOptions) Values

func (o *RequestOptions) Values() url.Values

Values returns the url.Values that set the request options defined by o.

type Time

type Time time.Time

A Time is a time.

func (Time) TimeString

func (t Time) TimeString() TimeString

TimeString returns t as a TimeString.

type TimePeriod

type TimePeriod struct {
	Start    time.Time
	Duration time.Duration
	Step     time.Duration
}

A TimePeriod is a time period.

func (TimePeriod) TimeString

func (p TimePeriod) TimeString() TimeString

TimeString returns p as a TimeString.

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
	Step  time.Duration
}

A TimeRange is a range of times.

func (TimeRange) TimeString

func (r TimeRange) TimeString() TimeString

TimeString returns r as a TimeString.

type TimeSlice

type TimeSlice []TimeStringer

A TimeSlice is a slice of TimeStringers.

func (TimeSlice) TimeString

func (s TimeSlice) TimeString() TimeString

TimeString returns s as a TimeString.

type TimeString

type TimeString string

A TimeString is a string representing a time.

const (
	TimeNow       TimeString = "now"
	TimeTomorrow  TimeString = "tomorrow"
	TimeYesterday TimeString = "yesterday"
)

Time shortcuts.

func (TimeString) TimeString

func (s TimeString) TimeString() TimeString

TimeString returns s as a TimeString.

type TimeStringer

type TimeStringer interface {
	TimeString() TimeString
}

A TimeStringer can be converted to a TimeString.

type TransportMethod

type TransportMethod string
const (
	MethodGet  TransportMethod = http.MethodGet
	MethodPost TransportMethod = http.MethodPost
)

type TransportOptions

type TransportOptions struct {
	Method string
}

type Units

type Units string

A Units is a string representing a unit.

const (
	UnitsBeaufort                  Units = "bft"
	UnitsCelsius                   Units = "C"
	UnitsDegrees                   Units = "d"
	UnitsFahrenheit                Units = "F"
	UnitsGramsPerCubicMeter        Units = "gm3"
	UnitsHectopascals              Units = "hPa"
	UnitsIndex                     Units = "idx"
	UnitsJoules                    Units = "J"
	UnitsJoulesPerKilogram         Units = "JKg"
	UnitsKelvin                    Units = "K"
	UnitsKilometersPerHour         Units = "kmh"
	UnitsKilogramsPerCubicMeter    Units = "kgm3"
	UnitsKnots                     Units = "kn"
	UnitsMeters                    Units = "m"
	UnitsMillimeters               Units = "mm"
	UnitsMetersPerSecond           Units = "ms"
	UnitsOctas                     Units = "octas"
	UnitsPercentage                Units = "p"
	UnitsPascals                   Units = "Pa"
	UnitsWattsPerSquareMeter       Units = "W"
	UnitsWattHoursPerSquareMeter   Units = "Wh"
	UnitsWattSecondsPerSquareMeter Units = "Ws"
)

Units.

Jump to

Keyboard shortcuts

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