weather

package
v0.0.0-...-bb60f61 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package weather contains utilities for obtaining weather statistics from weatherapi.com.

Index

Constants

This section is empty.

Variables

View Source
var ErrStatus = errors.New("unexpected status code")

ErrStatus is the error given when an HTTP call to weatherapi.com returns an error status code.

Functions

This section is empty.

Types

type Client

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

The Client type is used to interact with the weather API via HTTP.

func New

func New(apiKey string) (*Client, error)

New creates a new Client instance that will authenticate using the given api key.

func (*Client) GetWeather

func (cl *Client) GetWeather(ctx context.Context, location string) (*Weather, error)

GetWeather returns the current weather for a given location. Postcodes & city names are valid locations.

func (*Client) Ping

func (cl *Client) Ping() error

Ping determines if the connection to the API is healthy. If not, a non-nil error is returned.

type Condition

type Condition struct {
	Text string `json:"text"`
	Icon string `json:"icon"`
	Code int    `json:"code"`
}

The Condition type represents a summary of the current weather condition.

type GetCurrentWeatherResponse

type GetCurrentWeatherResponse struct {
	Location Location `json:"location"`
	Current  Weather  `json:"current"`
}

GetCurrentWeatherResponse represents the response body when requesting the current weather from the weather API.

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"`
	TzID           string  `json:"tz_id"`
	LocaltimeEpoch int     `json:"localtime_epoch"`
	Localtime      string  `json:"localtime"`
}

The Location type represents a unique location.

type Weather

type Weather struct {
	LastUpdatedEpoch int       `json:"last_updated_epoch"`
	LastUpdated      string    `json:"last_updated"`
	TempC            float64   `json:"temp_c"`
	TempF            float64   `json:"temp_f"`
	IsDay            float64   `json:"is_day"`
	Condition        Condition `json:"condition"`
	WindMph          float64   `json:"wind_mph"`
	WindKph          float64   `json:"wind_kph"`
	WindDegree       float64   `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         float64   `json:"humidity"`
	Cloud            float64   `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"`
}

The Weather type contains fields describing the weather.

Jump to

Keyboard shortcuts

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