httpclient

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

httpclient implements an API client for WeatherAPI https://www.weatherapi.com/docs/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Headline    string `json:"headline,omitempty"`
	MsgType     string `json:"msgtype,omitempty"`
	Severity    string `json:"severity,omitempty"`
	Urgency     string `json:"urgency,omitempty"`
	Areas       string `json:"areas,omitempty"`
	Category    string `json:"category,omitempty"`
	Certainty   string `json:"certainty,omitempty"`
	Event       string `json:"event,omitempty"`
	Note        string `json:"note,omitempty"`
	Effective   string `json:"effective,omitempty"`
	Expires     string `json:"expires,omitempty"`
	Description string `json:"desc,omitempty"`
	Instruction string `json:"instruction,omitempty"`
}

Alert is a weather alert or warning issued by a government agency

type AlertList

type AlertList struct {
	Alert []*Alert `json:"alert"`
}

AlertList is a list of weather alerts

type AlertsWeatherRequest

type AlertsWeatherRequest struct {
	Query    string `json:"query" help:"Location query (city name, coordinates, IP, etc.)"`
	Language string `json:"language,omitempty" help:"Language code (e.g., 'en', 'fr', 'es')"`
}

AlertsWeatherRequest defines the input for weather alerts query

func (*AlertsWeatherRequest) Values

func (r *AlertsWeatherRequest) Values(apiKey string) url.Values

Values converts AlertsWeatherRequest to URL query parameters

type Astro

type Astro struct {
	SunRise          string `json:"sunrise"`
	SunSet           string `json:"sunset"`
	MoonRise         string `json:"moonrise"`
	MoonSet          string `json:"moonset"`
	MoonPhase        string `json:"moon_phase"`
	MoonIllumination int    `json:"moon_illumination"`
	IsMoonUp         int    `json:"is_moon_up"`
	IsSunUp          int    `json:"is_sun_up"`
}

type Client

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

func New

func New(apiKey string, opts ...client.ClientOpt) (*Client, error)

New returns a client for WeatherAPI with the API key. The endpoint can be replaced with client.OptEndpoint, for example for testing.

func (*Client) Alerts

Alerts returns the weather alerts for the location in the request

func (*Client) Current

func (c *Client) Current(ctx context.Context, req *CurrentWeatherRequest) (Weather, error)

Current returns the current weather for the location in the request

func (*Client) Forecast

func (c *Client) Forecast(ctx context.Context, req *ForecastWeatherRequest) (Forecast, error)

Forecast returns the weather forecast for the location in the request

type Conditions

type Conditions struct {
	TempC     float64 `json:"temp_c"`
	TempF     float64 `json:"temp_f"`
	IsDay     int     `json:"is_day"` // Whether to show day condition icon (1) or night icon (0)
	Condition struct {
		Text string `json:"text"`
		Icon string `json:"icon"`
		Code int    `json:"code"`
	} `json:"condition"`
	WindMph    float64  `json:"wind_mph"`
	WindKph    float64  `json:"wind_kph"`
	WindDegree int      `json:"wind_degree"`
	WindDir    string   `json:"wind_dir"`
	PressureMb float64  `json:"pressure_mb"`
	PressureIn float64  `json:"pressure_in"`
	PrecipMm   float64  `json:"precip_mm"`
	PrecipIn   float64  `json:"precip_in"`
	Humidity   int      `json:"humidity"`
	Cloud      int      `json:"cloud"`
	FeelslikeC float64  `json:"feelslike_c"`
	FeelslikeF float64  `json:"feelslike_f"`
	VisKm      float64  `json:"vis_km"`
	VisMiles   float64  `json:"vis_miles"`
	Uv         float64  `json:"uv"`
	GustMph    float64  `json:"gust_mph"`
	GustKph    float64  `json:"gust_kph"`
	AirQuality Measures `json:"air_quality,omitempty"` // Returned when air quality is requested
	Pollen     Measures `json:"pollen,omitempty"`      // Returned when pollen is requested
}

type CurrentConditions

type CurrentConditions struct {
	LastUpdatedEpoch int64 `json:"last_updated_epoch"`
	LastUpdated      Time  `json:"last_updated"`
	Conditions
}

type CurrentWeatherRequest

type CurrentWeatherRequest struct {
	Query      string `json:"query" help:"Location query (city name, coordinates, IP, etc.)"`
	AirQuality bool   `json:"air_quality,omitempty" help:"Enable air quality data"`
	Pollen     bool   `json:"pollen,omitempty" help:"Enable pollen data"`
	Language   string `json:"language,omitempty" help:"Language code (e.g., 'en', 'fr', 'es')"`
}

CurrentWeatherRequest defines the input for current weather query

func (*CurrentWeatherRequest) Values

func (r *CurrentWeatherRequest) Values(apiKey string) url.Values

Values converts CurrentWeatherRequest to URL query parameters

type Day

type Day struct {
	MaxTempC            float64 `json:"maxtemp_c"`
	MaxTempF            float64 `json:"maxtemp_f"`
	MinTempC            float64 `json:"mintemp_c"`
	MinTempF            float64 `json:"mintemp_f"`
	AvgTempC            float64 `json:"avgtemp_c"`
	AvgTempF            float64 `json:"avgtemp_f"`
	MaxWindMph          float64 `json:"maxwind_mph"`
	MaxWindKph          float64 `json:"maxwind_kph"`
	TotalPrecipMm       float64 `json:"totalprecip_mm"`
	TotalPrecipIn       float64 `json:"totalprecip_in"`
	TotalSnowCm         float64 `json:"totalsnow_cm"`
	AvgVisKm            float64 `json:"avgvis_km"`
	AvgVisMiles         float64 `json:"avgvis_miles"`
	AvgHumidity         int     `json:"avghumidity"`
	WillItRain          int     `json:"daily_will_it_rain"`
	WillItSnow          int     `json:"daily_will_it_snow"`
	ChanceOfRainPercent int     `json:"daily_chance_of_rain"`
	ChanceOfSnowPercent int     `json:"daily_chance_of_snow"`
	Uv                  float32 `json:"uv"`
	Condition           struct {
		Text string `json:"text"`
		Icon string `json:"icon"`
		Code int    `json:"code"`
	} `json:"condition"`
	AirQuality Measures `json:"air_quality,omitempty"` // Returned when air quality is requested
}

type Forecast

type Forecast struct {
	Id       int                `json:"custom_id,omitempty"`
	Query    string             `json:"q,omitempty"`
	Location *Location          `json:"location,omitempty"`
	Current  *CurrentConditions `json:"current,omitempty"`
	Forecast struct {
		Day []*ForecastDay `json:"forecastday"`
	} `json:"forecast"`
	Alerts *AlertList `json:"alerts,omitempty"` // Returned when alerts are requested
}

func (Forecast) String

func (f Forecast) String() string

type ForecastConditions

type ForecastConditions struct {
	TimeEpoch int64 `json:"time_epoch"`
	Time      Time  `json:"time"`
	Conditions
}

type ForecastDay

type ForecastDay struct {
	Date      string                `json:"date"`
	DateEpoch int64                 `json:"date_epoch"`
	Day       *Day                  `json:"day"`
	Hour      []*ForecastConditions `json:"hour"`
	Astro     *Astro                `json:"astro"`
}

type ForecastWeatherRequest

type ForecastWeatherRequest struct {
	Query      string `json:"query" help:"Location query (city name, coordinates, IP, etc.)"`
	Days       int    `json:"days" help:"Number of days to forecast (1-14)" min:"1" max:"14"`
	Date       string `json:"date,omitempty" help:"Specific date for forecast (YYYY-MM-DD)"`
	AirQuality bool   `json:"air_quality,omitempty" help:"Enable air quality data"`
	Alerts     bool   `json:"alerts,omitempty" help:"Enable weather alerts"`
	Pollen     bool   `json:"pollen,omitempty" help:"Enable pollen data"`
	Language   string `json:"language,omitempty" help:"Language code (e.g., 'en', 'fr', 'es')"`
}

ForecastWeatherRequest defines the input for forecast weather query

func (*ForecastWeatherRequest) Values

func (r *ForecastWeatherRequest) Values(apiKey string) url.Values

Values converts ForecastWeatherRequest to URL query parameters

type Location

type Location struct {
	Name           string  `json:"name"`
	Region         string  `json:"region"`
	Country        string  `json:"country"`
	Lat            float64 `json:"lat"`
	Lon            float64 `json:"lon"`
	Timezone       string  `json:"tz_id"`
	LocaltimeEpoch int64   `json:"localtime_epoch"`
	Localtime      Time    `json:"localtime"`
}

type Measures

type Measures map[string]float64

Measures are measurements by name, such as the air quality's "pm2_5" or "us-epa-index", or the pollen's "Grass"

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a time in WeatherAPI's format, such as "2026-10-12 09:00", as UTC until it's set in the location's timezone, or in RFC 3339 format, which a time is written as, so a response can be read back

type Weather

type Weather struct {
	Id       int                `json:"custom_id,omitempty"`
	Query    string             `json:"q,omitempty"`
	Location *Location          `json:"location,omitempty"`
	Current  *CurrentConditions `json:"current,omitempty"`
}

func (Weather) String

func (w Weather) String() string

type WeatherAlerts

type WeatherAlerts struct {
	Query    string     `json:"q,omitempty"`
	Location *Location  `json:"location,omitempty"`
	Alerts   *AlertList `json:"alerts,omitempty"`
}

WeatherAlerts are the weather alerts for a location

func (WeatherAlerts) String

func (a WeatherAlerts) String() string

Jump to

Keyboard shortcuts

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