Documentation
¶
Index ¶
- Variables
- func GetCondition(code int) string
- func WindDirection(degrees int) string
- type Client
- func (c *Client) Current(ctx context.Context, location string) (*CurrentWeather, error)
- func (c *Client) CurrentByCoords(ctx context.Context, lat, lon float64, loc *Location) (*CurrentWeather, error)
- func (c *Client) Forecast(ctx context.Context, location string, days int, hourly bool) (*Forecast, error)
- func (c *Client) ForecastByCoords(ctx context.Context, lat, lon float64, days int, hourly bool, loc *Location) (*Forecast, error)
- func (c *Client) SearchLocation(ctx context.Context, query string) ([]Location, error)
- type CurrentWeather
- type DailyForecast
- type Forecast
- type HourlyForecast
- type Location
- type Options
Constants ¶
This section is empty.
Variables ¶
View Source
var WeatherCode = map[int]string{
0: "Clear sky",
1: "Mainly clear",
2: "Partly cloudy",
3: "Overcast",
45: "Foggy",
48: "Depositing rime fog",
51: "Light drizzle",
53: "Moderate drizzle",
55: "Dense drizzle",
56: "Light freezing drizzle",
57: "Dense freezing drizzle",
61: "Slight rain",
63: "Moderate rain",
65: "Heavy rain",
66: "Light freezing rain",
67: "Heavy freezing rain",
71: "Slight snow",
73: "Moderate snow",
75: "Heavy snow",
77: "Snow grains",
80: "Slight rain showers",
81: "Moderate rain showers",
82: "Violent rain showers",
85: "Slight snow showers",
86: "Heavy snow showers",
95: "Thunderstorm",
96: "Thunderstorm with slight hail",
99: "Thunderstorm with heavy hail",
}
WeatherCode maps WMO weather codes to human-readable conditions.
Functions ¶
func GetCondition ¶
GetCondition returns human-readable condition from weather code.
func WindDirection ¶
WindDirection returns compass direction from degrees.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles weather API requests.
func (*Client) CurrentByCoords ¶
func (c *Client) CurrentByCoords(ctx context.Context, lat, lon float64, loc *Location) (*CurrentWeather, error)
CurrentByCoords fetches current weather by coordinates.
func (*Client) Forecast ¶
func (c *Client) Forecast(ctx context.Context, location string, days int, hourly bool) (*Forecast, error)
Forecast fetches weather forecast for a location.
type CurrentWeather ¶
type CurrentWeather struct {
Location Location `json:"location"`
Time time.Time `json:"time"`
Temperature float64 `json:"temperature"` // °C
Apparent float64 `json:"apparent"` // Feels like °C
Humidity int `json:"humidity"` // %
Precipitation float64 `json:"precipitation"` // mm
Rain float64 `json:"rain"` // mm
Snowfall float64 `json:"snowfall"` // cm
WindSpeed float64 `json:"wind_speed"` // km/h
WindDirection int `json:"wind_direction"`
Pressure float64 `json:"pressure"` // hPa
CloudCover int `json:"cloud_cover"`
Visibility float64 `json:"visibility"` // meters
UVIndex float64 `json:"uv_index"`
WeatherCode int `json:"weather_code"`
Condition string `json:"condition"` // Human-readable
}
CurrentWeather represents current weather conditions.
type DailyForecast ¶
type DailyForecast struct {
Date time.Time `json:"date"`
TempMax float64 `json:"temp_max"`
TempMin float64 `json:"temp_min"`
ApparentMax float64 `json:"apparent_max"`
ApparentMin float64 `json:"apparent_min"`
Precipitation float64 `json:"precipitation"`
Rain float64 `json:"rain"`
Snowfall float64 `json:"snowfall"`
WindSpeedMax float64 `json:"wind_speed_max"`
WindDirection int `json:"wind_direction"`
UVIndexMax float64 `json:"uv_index_max"`
PrecipProb int `json:"precip_prob"` // %
Sunrise time.Time `json:"sunrise"`
Sunset time.Time `json:"sunset"`
WeatherCode int `json:"weather_code"`
Condition string `json:"condition"`
}
DailyForecast represents a single day's forecast.
type Forecast ¶
type Forecast struct {
Location Location `json:"location"`
Daily []DailyForecast `json:"daily,omitempty"`
Hourly []HourlyForecast `json:"hourly,omitempty"`
}
Forecast represents weather forecast data.
type HourlyForecast ¶
type HourlyForecast struct {
Time time.Time `json:"time"`
Temperature float64 `json:"temperature"`
Apparent float64 `json:"apparent"`
Humidity int `json:"humidity"`
Precipitation float64 `json:"precipitation"`
Rain float64 `json:"rain"`
Snowfall float64 `json:"snowfall"`
WindSpeed float64 `json:"wind_speed"`
WindDirection int `json:"wind_direction"`
Pressure float64 `json:"pressure"`
CloudCover int `json:"cloud_cover"`
Visibility float64 `json:"visibility"`
UVIndex float64 `json:"uv_index"`
PrecipProb int `json:"precip_prob"`
WeatherCode int `json:"weather_code"`
Condition string `json:"condition"`
}
HourlyForecast represents a single hour's forecast.
type Location ¶
type Location struct {
Name string `json:"name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Country string `json:"country,omitempty"`
Admin1 string `json:"admin1,omitempty"` // State/Province
Timezone string `json:"timezone,omitempty"`
}
Location represents a geographic location with coordinates.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
weathercli
command
Package main implements the weathercli CLI entrypoint.
|
Package main implements the weathercli CLI entrypoint. |
|
internal
|
|
Click to show internal directories.
Click to hide internal directories.