openmeteogo

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

OpenMeteo Go Client

License GoDoc

A simple and easy-to-use Go client for the Open-Meteo API. This library provides a convenient way to fetch current, historical, and forecasted weather data.

I built this mainly because I couldn't find historical support in the other go libraries for Open Meteo, and because it made for a fun weekend project.

Features

  • Fetch current, hourly, and daily weather data.
  • Access historical weather data for specific date ranges.
  • Fluent Options Builder for easily constructing complex queries.
  • Support for multiple units (Celsius/Fahrenheit, km/h/mph, etc.).
  • Select exactly which weather metrics you need.
  • Helper function to get human-readable descriptions from WMO weather codes.
  • Supports both the free and commercial (API key) Open-Meteo endpoints.

Installation

To install the library, use go get:

go get github.com/tpryan/openmeteogo

Usage

Here is a quick example of how to get the current weather and today's forecast for San Francisco.

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/tpryan/openmeteogo"
)

func main() {
	// 1. Create a new client
	c := openmeteogo.NewClient()

	// 2. Set the options for the weather data you want.
	// Use the fluent builder to easily configure your request.
	opts := openmeteogo.NewOptionsBuilder().
		Latitude(37.7749).
		Longitude(-122.4194).
		TemperatureUnit(openmeteogo.Fahrenheit).
		ForcastDays(1).
		CurrentMetrics(openmeteogo.Metrics{
			openmeteogo.Temperature2m,
			openmeteogo.WeatherCode,
		}).
		DailyMetrics(openmeteogo.Metrics{
			openmeteogo.Temperature2mMax,
			openmeteogo.Temperature2mMin,
			openmeteogo.WeatherCode,
		}).
		Build()

	// 3. Make the API call
	w, err := c.Get(opts)
	if err != nil {
		log.Fatalf("Failed to get weather data: %v", err)
	}

	// 4. Use the data!
	fmt.Printf("Current Weather in San Francisco (Lat: %.2f, Lon: %.2f)\n", w.Latitude, w.Longitude)
	fmt.Printf("Time: %s\n", w.Current.Time)
	fmt.Printf("Temperature: %.2f%s\n", w.Current.Temperature2m, w.CurrentUnits.Temperature2m)
	fmt.Printf("Weather: %s\n\n", openmeteogo.DescribeCode(w.Current.WeatherCode))

	// Print the daily forecast for today
	if len(w.Daily.Time) > 0 {
		fmt.Printf("Forecast for %s:\n", w.Daily.Time[0])
		fmt.Printf("  Max Temperature: %.2f%s\n", w.Daily.Temperature2mMax[0], w.DailyUnits.Temperature2mMax)
		fmt.Printf("  Min Temperature: %.2f%s\n", w.Daily.Temperature2mMin[0], w.DailyUnits.Temperature2mMin)
		fmt.Printf("  Weather: %s\n", openmeteogo.DescribeCode(w.Daily.WeatherCode[0]))
	}
}
Fetching Historical Data

To get historical data, simply provide a Start and End date. The client will automatically use the correct API endpoint.


    // Fetch historical data for a specific week
    pastOpts := openmeteogo.NewOptionsBuilder().
		Latitude(37.7749).
        Longitude(-122.4194).
		TemperatureUnit(openmeteogo.Fahrenheit).
		DailyMetrics(openmeteogo.Metrics{
			openmeteogo.Temperature2mMax,
			openmeteogo.Temperature2mMin,
			openmeteogo.WeatherCode,
		}).
		Start(time.Date(2023, 7, 1, 0, 0, 0, 0, time.UTC)).
        End(time.Date(2023, 7, 7, 0, 0, 0, 0, time.UTC)).
		Build()

	wp, err := c.Get(pastOpts)
	if err != nil {
		log.Fatalf("Failed to get historical weather data: %v", err)
	}

    // Process the historical daily data...
    for i, date := range wp.Daily.Time {
        fmt.Printf("Weather for %s:\n", date)
		fmt.Printf("  Max Temp: %.2f%s\n", wp.Daily.Temperature2mMax[i], wp.DailyUnits.Temperature2mMax)
		fmt.Printf("  Min Temp: %.2f%s\n", wp.Daily.Temperature2mMin[i], wp.DailyUnits.Temperature2mMin)
		fmt.Printf("  Weather: %s\n", openmeteogo.DescribeCode(wp.Daily.WeatherCode[i]))
    }

Options

The OptionsBuilder provides a simple way to configure your request.

Method Description Example
Latitude() Set the geographical latitude. .Latitude(37.7749)
Longitude() Set the geographical longitude. .Longitude(-122.4194)
TemperatureUnit() Set the temperature unit. (Celsius, Fahrenheit) .TemperatureUnit(openmeteogo.Celsius)
WindspeedUnit() Set the wind speed unit. (KMH, MPH, etc.) .WindspeedUnit(openmeteogo.MPH)
PrecipitationUnit() Set the precipitation unit. (MM, IN) .PrecipitationUnit(openmeteogo.IN)
Timezone() Set the timezone for results. .Timezone(*time.UTC)
PastDays() Request N number of past days of data. .PastDays(7)
ForcastDays() Request N number of forecast days. .ForcastDays(3)
Start() Set a start date for historical queries. .Start(time.Now())
End() Set an end date for historical queries. .End(time.Now())
CurrentMetrics() Select which current metrics to fetch. .CurrentMetrics(&CurrentMetrics{...})
DailyMetrics() Select which daily metrics to fetch. .DailyMetrics(&DailyMetrics{...})
HourlyMetrics() Select which hourly metrics to fetch. .HourlyMetrics(&HourlyMetrics{...})
Available Metrics

You can select exactly which weather variables you want by populating the CurrentMetrics, DailyMetrics, or HourlyMetrics with a slice of strings, that map directly to the JSON parameters in the Open-Meteo documentation.

You can request any combination of the following metrics.

Current Metrics

Temperature2m, RelativeHumidity2m, IsDay, ApparentTemperature, Precipitation, Rain, Showers, Snowfall, WeatherCode, CloudCover, PressureMsl, SurfacePressure, WindSpeed10m, WindDirection10m, WindGusts10m

Hourly Metrics

Temperature2m, RelativeHumidity2m, DewPoint2m, ApparentTemperature, PrecipitationProbability, Precipitation, Rain, Showers, Snowfall, SnowDepth, WeatherCode, PressureMsl, SurfacePressure, CloudCover, CloudCoverLow, CloudCoverMid, CloudCoverHigh, Evapotranspiration, Visibility, Et0FaoEvapotranspiration, VapourPressureDeficit, WindSpeed10m, WindSpeed80m, WindSpeed120m, WindSpeed180m, WindDirection10m, WindDirection80m, WindDirection120m, WindDirection180m, WindGusts10m, Temperature80m, Temperature120m, Temperature180m, SoilTemperature0cm, SoilTemperature6cm, SoilTemperature18cm, SoilTemperature54cm, SoilMoisture0To1cm, SoilMoisture1To3cm, SoilMoisture9To27cm, SoilMoisture3To9cm

Daily Metrics

WeatherCode, Temperature2mMax, Temperature2mMin, ApparentTemperatureMax, ApparentTemperatureMin, Sunrise, Sunset, SunshineDuration, DaylightDuration, UvIndexMax, UvIndexClearSkyMax, RainSum, ShowersSum, SnowfallSum, PrecipitationSum, PrecipitationHours, PrecipitationProbabilityMax, WindSpeed10mMax, WindGusts10mMax, WindDirection10mDominant, ShortwaveRadiationSum, Et0FaoEvapotranspiration

Available Units

You can specify the units for the following measurements:

  • Temperature: openmeteogo.Celsius (default), openmeteogo.Fahrenheit
  • Wind Speed: openmeteogo.KMH (default), openmeteogo.MS, openmeteogo.MPH, openmeteogo.KN
  • Precipitation: openmeteogo.MM (default), openmeteogo.IN

Example:

// Request only current temperature and wind speed
	opts := openmeteogo.NewOptionsBuilder().
		Latitude(37.77).
		Longitude(-122.41).
		TemperatureUnit(openmeteogo.Fahrenheit).
		CurrentMetrics(openmeteogo.Metrics{
			openmeteogo.Temperature2m,
			openmeteogo.WindSpeed10m,
		}).
		Build()

This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WeatherCodeMap = map[int]string{
	0:  "Clear sky",
	1:  "Mainly clear",
	2:  "Partly cloudy",
	3:  "Overcast",
	45: "Fog",
	48: "Depositing rime fog",
	51: "Drizzle: Light intensity",
	53: "Drizzle: Moderate intensity",
	55: "Drizzle: Dense intensity",
	56: "Freezing Drizzle: Light intensity",
	57: "Freezing Drizzle: Dense intensity",
	61: "Rain: Slight intensity",
	63: "Rain: Moderate intensity",
	65: "Rain: Heavy intensity",
	66: "Freezing Rain: Light intensity",
	67: "Freezing Rain: Heavy intensity",
	71: "Snow fall: Slight intensity",
	73: "Snow fall: Moderate intensity",
	75: "Snow fall: Heavy intensity",
	77: "Snow grains",
	80: "Rain showers: Slight",
	81: "Rain showers: Moderate",
	82: "Rain showers: Violent",
	85: "Snow showers: Slight",
	86: "Snow showers: Heavy",
	95: "Thunderstorm: Slight or moderate",
	96: "Thunderstorm with slight hail",
	99: "Thunderstorm with heavy hail",
}

WeatherCodeMap maps WMO weather codes to their descriptions. Based on WMO Code 4561.

Functions

func DescribeCode

func DescribeCode(code int) string

DescribeCode returns the string description for a given weather code. It returns "Unknown code" if the code is not found.

Types

type Client

type Client struct {
	// UserAgent is the string sent in the User-Agent header of the request.
	UserAgent string
	// HTTPClient allows for a custom http.Client to be used for requests.
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client is used to interact with the Open-Meteo API.

func NewClient

func NewClient() *Client

NewClient creates a new Client with default settings.

func NewClientWithKey

func NewClientWithKey(key string) *Client

NewClientWithKey creates a new Client configured with a commercial API key.

func (*Client) Get

func (c *Client) Get(o *Options) (*WeatherData, error)

Get fetches weather data based on the provided Options.

type Current

type Current struct {
	Time                string  `json:"time"`
	Interval            int     `json:"interval"`
	Temperature2m       float64 `json:"temperature_2m"`
	RelativeHumidity2m  int     `json:"relative_humidity_2m"`
	IsDay               int     `json:"is_day"`
	ApparentTemperature float64 `json:"apparent_temperature"`
	Precipitation       float64 `json:"precipitation"`
	Rain                float64 `json:"rain"`
	Showers             float64 `json:"showers"`
	Snowfall            float64 `json:"snowfall"`
	WeatherCode         int     `json:"weather_code"`
	CloudCover          int     `json:"cloud_cover"`
	PressureMsl         float64 `json:"pressure_msl"`
	SurfacePressure     float64 `json:"surface_pressure"`
	WindSpeed10m        float64 `json:"wind_speed_10m"`
	WindDirection10m    int     `json:"wind_direction_10m"`
	WindGusts10m        float64 `json:"wind_gusts_10m"`
}

Current holds the current weather data values.

type CurrentUnits

type CurrentUnits struct {
	Time                string `json:"time"`
	Interval            string `json:"interval"`
	Temperature2m       string `json:"temperature_2m"`
	RelativeHumidity2m  string `json:"relative_humidity_2m"`
	IsDay               string `json:"is_day"`
	ApparentTemperature string `json:"apparent_temperature"`
	Precipitation       string `json:"precipitation"`
	Rain                string `json:"rain"`
	Showers             string `json:"showers"`
	Snowfall            string `json:"snowfall"`
	WeatherCode         string `json:"weather_code"`
	CloudCover          string `json:"cloud_cover"`
	PressureMsl         string `json:"pressure_msl"`
	SurfacePressure     string `json:"surface_pressure"`
	WindSpeed10m        string `json:"wind_speed_10m"`
	WindDirection10m    string `json:"wind_direction_10m"`
	WindGusts10m        string `json:"wind_gusts_10m"`
}

CurrentUnits describes the units for the current weather data.

type Daily

type Daily struct {
	Time                        []string  `json:"time"`
	WeatherCode                 []int     `json:"weather_code"`
	Temperature2mMax            []float64 `json:"temperature_2m_max"`
	Temperature2mMin            []float64 `json:"temperature_2m_min"`
	ApparentTemperatureMax      []float64 `json:"apparent_temperature_max"`
	ApparentTemperatureMin      []float64 `json:"apparent_temperature_min"`
	Sunrise                     []string  `json:"sunrise"`
	Sunset                      []string  `json:"sunset"`
	SunshineDuration            []float64 `json:"sunshine_duration"`
	DaylightDuration            []float64 `json:"daylight_duration"`
	UvIndexMax                  []float64 `json:"uv_index_max"`
	UvIndexClearSkyMax          []float64 `json:"uv_index_clear_sky_max"`
	RainSum                     []float64 `json:"rain_sum"`
	ShowersSum                  []float64 `json:"showers_sum"`
	SnowfallSum                 []float64 `json:"snowfall_sum"`
	PrecipitationSum            []float64 `json:"precipitation_sum"`
	PrecipitationHours          []float64 `json:"precipitation_hours"`
	PrecipitationProbabilityMax []int     `json:"precipitation_probability_max"`
	WindSpeed10mMax             []float64 `json:"wind_speed_10m_max"`
	WindGusts10mMax             []float64 `json:"wind_gusts_10m_max"`
	WindDirection10mDominant    []int     `json:"wind_direction_10m_dominant"`
	ShortwaveRadiationSum       []float64 `json:"shortwave_radiation_sum"`
	Et0FaoEvapotranspiration    []float64 `json:"et0_fao_evapotranspiration"`
	WaveHeightMax               []float64 `json:"wave_height_max"`
	WaveDirectionDominant       []float64 `json:"wave_direction_dominant"`
	WavePeriodMax               []float64 `json:"wave_period_max"`
	WindWaveHeightMax           []float64 `json:"wind_wave_height_max"`
	WindWaveDirectionDominant   []float64 `json:"wind_wave_direction_dominant"`
	WindWavePeriodMax           []float64 `json:"wind_wave_period_max"`
	WindWavePeakPeriodMax       []float64 `json:"wind_wave_peak_period_max"`
	SwellWaveHeightMax          []float64 `json:"swell_wave_height_max"`
	SwellWaveDirectionDominant  []float64 `json:"swell_wave_direction_dominant"`
	SwellWavePeriodMax          []float64 `json:"swell_wave_period_max"`
	SwellWavePeakPeriodMax      []float64 `json:"swell_wave_peak_period_max"`
}

Daily holds slices for each daily forecast metric.

type DailyUnits

type DailyUnits struct {
	Time                        string `json:"time"`
	WeatherCode                 string `json:"weather_code"`
	Temperature2mMax            string `json:"temperature_2m_max"`
	Temperature2mMin            string `json:"temperature_2m_min"`
	ApparentTemperatureMax      string `json:"apparent_temperature_max"`
	ApparentTemperatureMin      string `json:"apparent_temperature_min"`
	Sunrise                     string `json:"sunrise"`
	Sunset                      string `json:"sunset"`
	SunshineDuration            string `json:"sunshine_duration"`
	DaylightDuration            string `json:"daylight_duration"`
	UvIndexMax                  string `json:"uv_index_max"`
	UvIndexClearSkyMax          string `json:"uv_index_clear_sky_max"`
	RainSum                     string `json:"rain_sum"`
	ShowersSum                  string `json:"showers_sum"`
	SnowfallSum                 string `json:"snowfall_sum"`
	PrecipitationSum            string `json:"precipitation_sum"`
	PrecipitationHours          string `json:"precipitation_hours"`
	PrecipitationProbabilityMax string `json:"precipitation_probability_max"`
	WindSpeed10mMax             string `json:"wind_speed_10m_max"`
	WindGusts10mMax             string `json:"wind_gusts_10m_max"`
	WindDirection10mDominant    string `json:"wind_direction_10m_dominant"`
	ShortwaveRadiationSum       string `json:"shortwave_radiation_sum"`
	Et0FaoEvapotranspiration    string `json:"et0_fao_evapotranspiration"`
	WaveHeightMax               string `json:"wave_height_max"`
	WaveDirectionDominant       string `json:"wave_direction_dominant"`
	WavePeriodMax               string `json:"wave_period_max"`
	WindWaveHeightMax           string `json:"wind_wave_height_max"`
	WindWaveDirectionDominant   string `json:"wind_wave_direction_dominant"`
	WindWavePeriodMax           string `json:"wind_wave_period_max"`
	WindWavePeakPeriodMax       string `json:"wind_wave_peak_period_max"`
	SwellWaveHeightMax          string `json:"swell_wave_height_max"`
	SwellWaveDirectionDominant  string `json:"swell_wave_direction_dominant"`
	SwellWavePeriodMax          string `json:"swell_wave_period_max"`
	SwellWavePeakPeriodMax      string `json:"swell_wave_peak_period_max"`
}

DailyUnits describes the units for the daily forecast data.

type Hourly

type Hourly struct {
	Time                        []string  `json:"time"`
	Temperature2m               []float64 `json:"temperature_2m"`
	RelativeHumidity2m          []int     `json:"relative_humidity_2m"`
	DewPoint2m                  []float64 `json:"dew_point_2m"`
	ApparentTemperature         []float64 `json:"apparent_temperature"`
	PrecipitationProbability    []int     `json:"precipitation_probability"`
	Precipitation               []float64 `json:"precipitation"`
	Rain                        []float64 `json:"rain"`
	Showers                     []float64 `json:"showers"`
	Snowfall                    []float64 `json:"snowfall"`
	SnowDepth                   []float64 `json:"snow_depth"`
	WeatherCode                 []int     `json:"weather_code"`
	PressureMsl                 []float64 `json:"pressure_msl"`
	SurfacePressure             []float64 `json:"surface_pressure"`
	CloudCover                  []int     `json:"cloud_cover"`
	CloudCoverLow               []int     `json:"cloud_cover_low"`
	CloudCoverMid               []int     `json:"cloud_cover_mid"`
	CloudCoverHigh              []int     `json:"cloud_cover_high"`
	Evapotranspiration          []float64 `json:"evapotranspiration"`
	Visibility                  []float64 `json:"visibility"`
	Et0FaoEvapotranspiration    []float64 `json:"et0_fao_evapotranspiration"`
	VapourPressureDeficit       []float64 `json:"vapour_pressure_deficit"`
	WindSpeed10m                []float64 `json:"wind_speed_10m"`
	WindSpeed80m                []float64 `json:"wind_speed_80m"`
	WindSpeed120m               []float64 `json:"wind_speed_120m"`
	WindSpeed180m               []float64 `json:"wind_speed_180m"`
	WindDirection10m            []int     `json:"wind_direction_10m"`
	WindDirection80m            []int     `json:"wind_direction_80m"`
	WindDirection120m           []int     `json:"wind_direction_120m"`
	WindDirection180m           []int     `json:"wind_direction_180m"`
	WindGusts10m                []float64 `json:"wind_gusts_10m"`
	Temperature80m              []float64 `json:"temperature_80m"`
	Temperature120m             []float64 `json:"temperature_120m"`
	Temperature180m             []float64 `json:"temperature_180m"`
	SoilTemperature0cm          []float64 `json:"soil_temperature_0cm"`
	SoilTemperature6cm          []float64 `json:"soil_temperature_6cm"`
	SoilTemperature18cm         []float64 `json:"soil_temperature_18cm"`
	SoilTemperature54cm         []float64 `json:"soil_temperature_54cm"`
	SoilMoisture0To1cm          []float64 `json:"soil_moisture_0_to_1cm"`
	SoilMoisture1To3cm          []float64 `json:"soil_moisture_1_to_3cm"`
	SoilMoisture9To27cm         []float64 `json:"soil_moisture_9_to_27cm"`
	SoilMoisture3To9cm          []float64 `json:"soil_moisture_3_to_9cm"`
	WaveHeight                  []float64 `json:"wave_height"`
	WaveDirection               []float64 `json:"wave_direction"`
	WavePeriod                  []float64 `json:"wave_period"`
	WavePeakPeriod              []float64 `json:"wave_peak_period"`
	WindWaveHeight              []float64 `json:"wind_wave_height"`
	WindWaveDirection           []float64 `json:"wind_wave_direction"`
	WindWavePeriod              []float64 `json:"wind_wave_period"`
	WindWavePeakPeriod          []float64 `json:"wind_wave_peak_period"`
	SwellWaveHeight             []float64 `json:"swell_wave_height"`
	SwellWaveDirection          []float64 `json:"swell_wave_direction"`
	SwellWavePeriod             []float64 `json:"swell_wave_period"`
	SwellWavePeakPeriod         []float64 `json:"swell_wave_peak_period"`
	SecondarySwellWaveHeight    []float64 `json:"secondary_swell_wave_height"`
	SecondarySwellWaveDirection []float64 `json:"secondary_swell_wave_direction"`
	SecondarySwellWavePeriod    []float64 `json:"secondary_swell_wave_period"`
	TertiarySwellWaveHeight     []float64 `json:"tertiary_swell_wave_height"`
	TertiarySwellWaveDirection  []float64 `json:"tertiary_swell_wave_direction"`
	TertiarySwellWavePeriod     []float64 `json:"tertiary_swell_wave_period"`
	SeaLevelHeight              []float64 `json:"sea_level_height"`
	SeaSurfaceTemperature       []float64 `json:"sea_surface_temperature"`
	OceanCurrentVelocity        []float64 `json:"ocean_current_velocity"`
	OceanCurrentDirection       []float64 `json:"ocean_current_direction"`
}

Hourly holds slices for each hourly forecast metric.

type HourlyUnits

type HourlyUnits struct {
	Time                        string `json:"time"`
	Temperature2m               string `json:"temperature_2m"`
	RelativeHumidity2m          string `json:"relative_humidity_2m"`
	DewPoint2m                  string `json:"dew_point_2m"`
	ApparentTemperature         string `json:"apparent_temperature"`
	PrecipitationProbability    string `json:"precipitation_probability"`
	Precipitation               string `json:"precipitation"`
	Rain                        string `json:"rain"`
	Showers                     string `json:"showers"`
	Snowfall                    string `json:"snowfall"`
	SnowDepth                   string `json:"snow_depth"`
	WeatherCode                 string `json:"weather_code"`
	PressureMsl                 string `json:"pressure_msl"`
	SurfacePressure             string `json:"surface_pressure"`
	CloudCover                  string `json:"cloud_cover"`
	CloudCoverLow               string `json:"cloud_cover_low"`
	CloudCoverMid               string `json:"cloud_cover_mid"`
	CloudCoverHigh              string `json:"cloud_cover_high"`
	Evapotranspiration          string `json:"evapotranspiration"`
	Visibility                  string `json:"visibility"`
	Et0FaoEvapotranspiration    string `json:"et0_fao_evapotranspiration"`
	VapourPressureDeficit       string `json:"vapour_pressure_deficit"`
	WindSpeed10m                string `json:"wind_speed_10m"`
	WindSpeed80m                string `json:"wind_speed_80m"`
	WindSpeed120m               string `json:"wind_speed_120m"`
	WindSpeed180m               string `json:"wind_speed_180m"`
	WindDirection10m            string `json:"wind_direction_10m"`
	WindDirection80m            string `json:"wind_direction_80m"`
	WindDirection120m           string `json:"wind_direction_120m"`
	WindDirection180m           string `json:"wind_direction_180m"`
	WindGusts10m                string `json:"wind_gusts_10m"`
	Temperature80m              string `json:"temperature_80m"`
	Temperature120m             string `json:"temperature_120m"`
	Temperature180m             string `json:"temperature_180m"`
	SoilTemperature0cm          string `json:"soil_temperature_0cm"`
	SoilTemperature6cm          string `json:"soil_temperature_6cm"`
	SoilTemperature18cm         string `json:"soil_temperature_18cm"`
	SoilTemperature54cm         string `json:"soil_temperature_54cm"`
	SoilMoisture0To1cm          string `json:"soil_moisture_0_to_1cm"`
	SoilMoisture1To3cm          string `json:"soil_moisture_1_to_3cm"`
	SoilMoisture9To27cm         string `json:"soil_moisture_9_to_27cm"`
	SoilMoisture3To9cm          string `json:"soil_moisture_3_to_9cm"`
	WaveHeight                  string `json:"wave_height"`
	WaveDirection               string `json:"wave_direction"`
	WavePeriod                  string `json:"wave_period"`
	WavePeakPeriod              string `json:"wave_peak_period"`
	WindWaveHeight              string `json:"wind_wave_height"`
	WindWaveDirection           string `json:"wind_wave_direction"`
	WindWavePeriod              string `json:"wind_wave_period"`
	WindWavePeakPeriod          string `json:"wind_wave_peak_period"`
	SwellWaveHeight             string `json:"swell_wave_height"`
	SwellWaveDirection          string `json:"swell_wave_direction"`
	SwellWavePeriod             string `json:"swell_wave_period"`
	SwellWavePeakPeriod         string `json:"swell_wave_peak_period"`
	SecondarySwellWaveHeight    string `json:"secondary_swell_wave_height"`
	SecondarySwellWaveDirection string `json:"secondary_swell_wave_direction"`
	SecondarySwellWavePeriod    string `json:"secondary_swell_wave_period"`
	TertiarySwellWaveHeight     string `json:"tertiary_swell_wave_height"`
	TertiarySwellWaveDirection  string `json:"tertiary_swell_wave_direction"`
	TertiarySwellWavePeriod     string `json:"tertiary_swell_wave_period"`
	SeaLevelHeight              string `json:"sea_level_height"`
	SeaSurfaceTemperature       string `json:"sea_surface_temperature"`
	OceanCurrentVelocity        string `json:"ocean_current_velocity"`
	OceanCurrentDirection       string `json:"ocean_current_direction"`
}

HourlyUnits describes the units for the hourly forecast data.

type Metric

type Metric string
const (
	Temperature2m               Metric = "temperature_2m"
	RelativeHumidity2m          Metric = "relative_humidity_2m"
	DewPoint2m                  Metric = "dew_point_2m"
	ApparentTemperature         Metric = "apparent_temperature"
	PrecipitationProbability    Metric = "precipitation_probability"
	Precipitation               Metric = "precipitation"
	Rain                        Metric = "rain"
	Showers                     Metric = "showers"
	Snowfall                    Metric = "snowfall"
	SnowDepth                   Metric = "snow_depth"
	WeatherCode                 Metric = "weather_code"
	PressureMsl                 Metric = "pressure_msl"
	SurfacePressure             Metric = "surface_pressure"
	CloudCover                  Metric = "cloud_cover"
	CloudCoverLow               Metric = "cloud_cover_low"
	CloudCoverMid               Metric = "cloud_cover_mid"
	CloudCoverHigh              Metric = "cloud_cover_high"
	Evapotranspiration          Metric = "evapotranspiration"
	Visibility                  Metric = "visibility"
	Et0FaoEvapotranspiration    Metric = "et0_fao_evapotranspiration"
	VapourPressureDeficit       Metric = "vapour_pressure_deficit"
	WindSpeed10m                Metric = "wind_speed_10m"
	WindSpeed80m                Metric = "wind_speed_80m"
	WindSpeed120m               Metric = "wind_speed_120m"
	WindSpeed180m               Metric = "wind_speed_180m"
	WindDirection10m            Metric = "wind_direction_10m"
	WindDirection80m            Metric = "wind_direction_80m"
	WindDirection120m           Metric = "wind_direction_120m"
	WindDirection180m           Metric = "wind_direction_180m"
	WindGusts10m                Metric = "wind_gusts_10m"
	Temperature80m              Metric = "temperature_80m"
	Temperature120m             Metric = "temperature_120m"
	Temperature180m             Metric = "temperature_180m"
	SoilTemperature0cm          Metric = "soil_temperature_0cm"
	SoilTemperature6cm          Metric = "soil_temperature_6cm"
	SoilTemperature18cm         Metric = "soil_temperature_18cm"
	SoilTemperature54cm         Metric = "soil_temperature_54cm"
	SoilMoisture0To1cm          Metric = "soil_moisture_0_to_1cm"
	SoilMoisture1To3cm          Metric = "soil_moisture_1_to_3cm"
	SoilMoisture9To27cm         Metric = "soil_moisture_9_to_27cm"
	SoilMoisture3To9cm          Metric = "soil_moisture_3_to_9cm"
	IsDay                       Metric = "is_day"
	Temperature2mMax            Metric = "temperature_2m_max"
	Temperature2mMin            Metric = "temperature_2m_min"
	ApparentTemperatureMax      Metric = "apparent_temperature_max"
	ApparentTemperatureMin      Metric = "apparent_temperature_min"
	Sunrise                     Metric = "sunrise"
	Sunset                      Metric = "sunset"
	SunshineDuration            Metric = "sunshine_duration"
	DaylightDuration            Metric = "daylight_duration"
	UvIndexMax                  Metric = "uv_index_max"
	UvIndexClearSkyMax          Metric = "uv_index_clear_sky_max"
	RainSum                     Metric = "rain_sum"
	ShowersSum                  Metric = "showers_sum"
	SnowfallSum                 Metric = "snowfall_sum"
	PrecipitationSum            Metric = "precipitation_sum"
	PrecipitationHours          Metric = "precipitation_hours"
	PrecipitationProbabilityMax Metric = "precipitation_probability_max"
	WindSpeed10mMax             Metric = "wind_speed_10m_max"
	WindGusts10mMax             Metric = "wind_gusts_10m_max"
	WindDirection10mDominant    Metric = "wind_direction_10m_dominant"
	ShortwaveRadiationSum       Metric = "shortwave_radiation_sum"

	// Seasonal Metrics (Weekly & Monthly)
	Temperature2mMean          Metric = "temperature_2m_mean"
	Temperature2mAnomaly       Metric = "temperature_2m_anomaly"
	Temperature2mMaxMean       Metric = "temperature_2m_max_mean"
	Temperature2mMinMean       Metric = "temperature_2m_min_mean"
	DewPoint2mMean             Metric = "dew_point_2m_mean"
	PrecipitationMean          Metric = "precipitation_mean"
	PrecipitationAnomaly       Metric = "precipitation_anomaly"
	PressureMslMean            Metric = "pressure_msl_mean"
	PressureMslAnomaly         Metric = "pressure_msl_anomaly"
	SoilMoisture0To10cmMean    Metric = "soil_moisture_0_to_10cm_mean"
	SoilMoisture0To10cmAnomaly Metric = "soil_moisture_0_to_10cm_anomaly"

	// Marine Metrics (Hourly)
	WaveHeight                  Metric = "wave_height"
	WaveDirection               Metric = "wave_direction"
	WavePeriod                  Metric = "wave_period"
	WavePeakPeriod              Metric = "wave_peak_period"
	WindWaveHeight              Metric = "wind_wave_height"
	WindWaveDirection           Metric = "wind_wave_direction"
	WindWavePeriod              Metric = "wind_wave_period"
	WindWavePeakPeriod          Metric = "wind_wave_peak_period"
	SwellWaveHeight             Metric = "swell_wave_height"
	SwellWaveDirection          Metric = "swell_wave_direction"
	SwellWavePeriod             Metric = "swell_wave_period"
	SwellWavePeakPeriod         Metric = "swell_wave_peak_period"
	SecondarySwellWaveHeight    Metric = "secondary_swell_wave_height"
	SecondarySwellWaveDirection Metric = "secondary_swell_wave_direction"
	SecondarySwellWavePeriod    Metric = "secondary_swell_wave_period"
	TertiarySwellWaveHeight     Metric = "tertiary_swell_wave_height"
	TertiarySwellWaveDirection  Metric = "tertiary_swell_wave_direction"
	TertiarySwellWavePeriod     Metric = "tertiary_swell_wave_period"
	SeaLevelHeight              Metric = "sea_level_height"
	SeaSurfaceTemperature       Metric = "sea_surface_temperature"
	OceanCurrentVelocity        Metric = "ocean_current_velocity"
	OceanCurrentDirection       Metric = "ocean_current_direction"

	// Marine Metrics (Daily)
	WaveHeightMax              Metric = "wave_height_max"
	WaveDirectionDominant      Metric = "wave_direction_dominant"
	WavePeriodMax              Metric = "wave_period_max"
	WindWaveHeightMax          Metric = "wind_wave_height_max"
	WindWaveDirectionDominant  Metric = "wind_wave_direction_dominant"
	WindWavePeriodMax          Metric = "wind_wave_period_max"
	WindWavePeakPeriodMax      Metric = "wind_wave_peak_period_max"
	SwellWaveHeightMax         Metric = "swell_wave_height_max"
	SwellWaveDirectionDominant Metric = "swell_wave_direction_dominant"
	SwellWavePeriodMax         Metric = "swell_wave_period_max"
	SwellWavePeakPeriodMax     Metric = "swell_wave_peak_period_max"
)

type Metrics

type Metrics []Metric

func NewMetrics

func NewMetrics(metricType string, Metrics ...Metric) (Metrics, error)

type Monthly added in v1.1.0

type Monthly struct {
	Time                    []string  `json:"time"`
	Temperature2mMean       []float64 `json:"temperature_2m_mean"`
	Temperature2mAnomaly    []float64 `json:"temperature_2m_anomaly"`
	PrecipitationMean       []float64 `json:"precipitation_mean"`
	PrecipitationAnomaly    []float64 `json:"precipitation_anomaly"`
	PressureMslMean         []float64 `json:"pressure_msl_mean"`
	PressureMslAnomaly      []float64 `json:"pressure_msl_anomaly"`
	SoilMoisture0To10cmMean []float64 `json:"soil_moisture_0_to_10cm_mean"`
}

Monthly holds slices for each monthly seasonal forecast metric.

type MonthlyUnits added in v1.1.0

type MonthlyUnits struct {
	Time                    string `json:"time"`
	Temperature2mMean       string `json:"temperature_2m_mean"`
	Temperature2mAnomaly    string `json:"temperature_2m_anomaly"`
	PrecipitationMean       string `json:"precipitation_mean"`
	PrecipitationAnomaly    string `json:"precipitation_anomaly"`
	PressureMslMean         string `json:"pressure_msl_mean"`
	PressureMslAnomaly      string `json:"pressure_msl_anomaly"`
	SoilMoisture0To10cmMean string `json:"soil_moisture_0_to_10cm_mean"`
}

MonthlyUnits describes the units for the monthly seasonal forecast data.

type Options

type Options struct {
	// Latitude for the location to which the weather forecast refers.
	Latitude float64
	// Longitude for the location to which the weather forecast refers.
	Longitude float64
	// TemperatureUnit sets the unit for temperature values. Default is Celsius.
	TemperatureUnit TemperatureUnit
	// WindspeedUnit sets the unit for wind speed values. Default is km/h.
	WindspeedUnit WindSpeedUnit
	// PrecipitationUnit sets the unit for precipitation values. Default is millimeters.
	PrecipitationUnit PrecipitationUnit
	// Timezone for the forecast data. Default is UTC.
	Timezone time.Location
	// PastDays specifies how many days of historical data to retrieve. Default is 0.
	PastDays int
	// ForcastDays specifies how many days of forecast data to retrieve.
	ForcastDays int
	// Start date for the historical data query.
	Start time.Time
	// End date for the historical data query.
	End time.Time
	// Models specifies the weather models to use (e.g. "ecmwf_seas5").
	Models []string
	// HourlyMetrics specifies which hourly weather variables to retrieve.
	HourlyMetrics Metrics
	// DailyMetrics specifies which daily weather variables to retrieve.
	DailyMetrics Metrics
	// WeeklyMetrics specifies which weekly weather variables to retrieve (Seasonal API).
	WeeklyMetrics Metrics
	// MonthlyMetrics specifies which monthly weather variables to retrieve (Seasonal API).
	MonthlyMetrics Metrics
	// CurrentMetrics specifies which current weather variables to retrieve.
	CurrentMetrics Metrics
	// Seasonal forces the request to use the seasonal API endpoint.
	Seasonal bool
	// Marine forces the request to use the marine API endpoint.
	Marine bool
}

Options holds all the parameters for a weather data request. It is configured using the OptionsBuilder.

type OptionsBuilder

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

OptionsBuilder provides a fluent interface for constructing an Options object.

func NewOptionsBuilder

func NewOptionsBuilder() *OptionsBuilder

NewOptionsBuilder creates a new OptionsBuilder with default options.

func (*OptionsBuilder) Build

func (b *OptionsBuilder) Build() *Options

Build finalizes the construction and returns the configured Options object.

func (*OptionsBuilder) CurrentMetrics

func (b *OptionsBuilder) CurrentMetrics(metrics Metrics) *OptionsBuilder

CurrentMetrics sets the specific current weather metrics to be fetched.

func (*OptionsBuilder) DailyMetrics

func (b *OptionsBuilder) DailyMetrics(metrics Metrics) *OptionsBuilder

DailyMetrics sets the specific daily metrics to be fetched.

func (*OptionsBuilder) End

func (b *OptionsBuilder) End(end time.Time) *OptionsBuilder

End sets the end date for a specific time-range query.

func (*OptionsBuilder) ForcastDays

func (b *OptionsBuilder) ForcastDays(days int) *OptionsBuilder

ForcastDays sets the number of future days to retrieve data for.

func (*OptionsBuilder) HourlyMetrics

func (b *OptionsBuilder) HourlyMetrics(metrics Metrics) *OptionsBuilder

HourlyMetrics sets the specific hourly metrics to be fetched.

func (*OptionsBuilder) Latitude

func (b *OptionsBuilder) Latitude(lat float64) *OptionsBuilder

Latitude sets the geographical latitude for the request.

func (*OptionsBuilder) Longitude

func (b *OptionsBuilder) Longitude(lon float64) *OptionsBuilder

Longitude sets the geographical longitude for the request.

func (*OptionsBuilder) Marine added in v1.2.0

func (b *OptionsBuilder) Marine(marine bool) *OptionsBuilder

Marine forces the request to use the marine API endpoint.

func (*OptionsBuilder) Models added in v1.1.0

func (b *OptionsBuilder) Models(models []string) *OptionsBuilder

Models sets the specific weather models to be used.

func (*OptionsBuilder) MonthlyMetrics added in v1.1.0

func (b *OptionsBuilder) MonthlyMetrics(metrics Metrics) *OptionsBuilder

MonthlyMetrics sets the specific monthly metrics to be fetched (Seasonal API).

func (*OptionsBuilder) PastDays

func (b *OptionsBuilder) PastDays(days int) *OptionsBuilder

PastDays sets the number of past days to retrieve data for.

func (*OptionsBuilder) PrecipitationUnit

func (b *OptionsBuilder) PrecipitationUnit(unit PrecipitationUnit) *OptionsBuilder

PrecipitationUnit sets the desired unit for precipitation measurements.

func (*OptionsBuilder) Seasonal added in v1.1.0

func (b *OptionsBuilder) Seasonal(seasonal bool) *OptionsBuilder

Seasonal forces the request to use the seasonal API endpoint.

func (*OptionsBuilder) Start

func (b *OptionsBuilder) Start(start time.Time) *OptionsBuilder

Start sets the start date for a specific time-range query.

func (*OptionsBuilder) TemperatureUnit

func (b *OptionsBuilder) TemperatureUnit(unit TemperatureUnit) *OptionsBuilder

TemperatureUnit sets the desired unit for temperature measurements.

func (*OptionsBuilder) Timezone

func (b *OptionsBuilder) Timezone(tz time.Location) *OptionsBuilder

Timezone sets the timezone for the returned data.

func (*OptionsBuilder) WeeklyMetrics added in v1.1.0

func (b *OptionsBuilder) WeeklyMetrics(metrics Metrics) *OptionsBuilder

WeeklyMetrics sets the specific weekly metrics to be fetched (Seasonal API).

func (*OptionsBuilder) WindspeedUnit

func (b *OptionsBuilder) WindspeedUnit(unit WindSpeedUnit) *OptionsBuilder

WindspeedUnit sets the desired unit for wind speed measurements.

type PrecipitationUnit

type PrecipitationUnit string

PrecipitationUnit defines the unit for precipitation values.

const (
	// MM is the default precipitation unit (millimeters).
	MM PrecipitationUnit = "mm"
	// IN is inches.
	IN PrecipitationUnit = "in"
)

type TemperatureUnit

type TemperatureUnit string

TemperatureUnit defines the unit for temperature values.

const (
	// Celsius is the default temperature unit.
	Celsius TemperatureUnit = "celsius"
	// Fahrenheit temperature unit.
	Fahrenheit TemperatureUnit = "fahrenheit"
)

type WeatherData

type WeatherData struct {
	Latitude             float64      `json:"latitude"`
	Longitude            float64      `json:"longitude"`
	GenerationtimeMs     float64      `json:"generationtime_ms"`
	UtcOffsetSeconds     int          `json:"utc_offset_seconds"`
	Timezone             string       `json:"timezone"`
	TimezoneAbbreviation string       `json:"timezone_abbreviation"`
	Elevation            float64      `json:"elevation"`
	CurrentUnits         CurrentUnits `json:"current_units"`
	Current              Current      `json:"current"`
	HourlyUnits          HourlyUnits  `json:"hourly_units"`
	Hourly               Hourly       `json:"hourly"`
	DailyUnits           DailyUnits   `json:"daily_units"`
	Daily                Daily        `json:"daily"`
	WeeklyUnits          WeeklyUnits  `json:"weekly_units"`
	Weekly               Weekly       `json:"weekly"`
	MonthlyUnits         MonthlyUnits `json:"monthly_units"`
	Monthly              Monthly      `json:"monthly"`
}

WeatherData is the main struct that holds all the data returned from the API.

type Weekly added in v1.1.0

type Weekly struct {
	Time                    []string  `json:"time"`
	Temperature2mMean       []float64 `json:"temperature_2m_mean"`
	Temperature2mAnomaly    []float64 `json:"temperature_2m_anomaly"`
	PrecipitationMean       []float64 `json:"precipitation_mean"`
	PrecipitationAnomaly    []float64 `json:"precipitation_anomaly"`
	PressureMslMean         []float64 `json:"pressure_msl_mean"`
	PressureMslAnomaly      []float64 `json:"pressure_msl_anomaly"`
	SoilMoisture0To10cmMean []float64 `json:"soil_moisture_0_to_10cm_mean"`
}

Weekly holds slices for each weekly seasonal forecast metric.

type WeeklyUnits added in v1.1.0

type WeeklyUnits struct {
	Time                    string `json:"time"`
	Temperature2mMean       string `json:"temperature_2m_mean"`
	Temperature2mAnomaly    string `json:"temperature_2m_anomaly"`
	PrecipitationMean       string `json:"precipitation_mean"`
	PrecipitationAnomaly    string `json:"precipitation_anomaly"`
	PressureMslMean         string `json:"pressure_msl_mean"`
	PressureMslAnomaly      string `json:"pressure_msl_anomaly"`
	SoilMoisture0To10cmMean string `json:"soil_moisture_0_to_10cm_mean"`
}

WeeklyUnits describes the units for the weekly seasonal forecast data.

type WindSpeedUnit

type WindSpeedUnit string

WindSpeedUnit defines the unit for wind speed values.

const (
	// KMH is the default wind speed unit (kilometers per hour).
	KMH WindSpeedUnit = "kmh"
	// MS is meters per second.
	MS WindSpeedUnit = "ms"
	// MPH is miles per hour.
	MPH WindSpeedUnit = "mph"
	// KN is knots.
	KN WindSpeedUnit = "kn"
)

Jump to

Keyboard shortcuts

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