openweather

package module
v0.0.0-...-20316a1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2018 License: MIT Imports: 6 Imported by: 0

README

GO-OPENWEATHER

Go Report Card GoDoc

go-openweather is a library/wrapper for the OpenWeather API that is written in Go.

Features:

Has the basic access to the OpenWeather API:

  • Get the weather by City name, City ID, Coordinates, Zip Code;
  • Get Forecast Data

Installation:

$ go get -u github.com/rbo13/go-openweather

How to use:

client := openweather.NewClient("OPENWEATHER_API_KEY")

// Get Current Weather By City name
weatherData, err := client.GetWeatherByCityName("London")

// validation removed for brevity
log.Print(weatherData)

TODO:

  • Get Forecast Data
  • Add more test

LICENSE:

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the client request to openweather api

func NewClient

func NewClient(apiKey string) *Client

NewClient returns the Client struct

func (*Client) GetDailyForecastByCityID

func (c *Client) GetDailyForecastByCityID(cityID, count string) (*DailyForecastData, error)

GetDailyForecastByCityID returns the daily forecast by a given city id and count/frequency of the forecast. Sets default value to count if none is specified.

func (*Client) GetDailyForecastByCityName

func (c *Client) GetDailyForecastByCityName(cityName, unit, count string) (*DailyForecastData, error)

GetDailyForecastByCityName returns the daily forecast by a given city name, unit and count/frequency of the forecast. Sets default value for unit and count if none is specified.

func (*Client) GetDailyForecastByCoordinates

func (c *Client) GetDailyForecastByCoordinates(coords Coordinates, count string) (*DailyForecastData, error)

GetDailyForecastByCoordinates returns the daily forecast by a given city id and count/frequency of the forecast. Sets default value to count if none is specified.

func (*Client) GetForecastByCityID

func (c *Client) GetForecastByCityID(cityID string) (*ForecastData, error)

GetForecastByCityID returns the forecast by a given city id Sample: https://samples.openweathermap.org/data/2.5/forecast?id=524901&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetForecastByCityName

func (c *Client) GetForecastByCityName(cityName string) (*ForecastData, error)

GetForecastByCityName returns the forecast by a given city Sample: https://samples.openweathermap.org/data/2.5/forecast?q=London,us&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetForecastByCoordinates

func (c *Client) GetForecastByCoordinates(coords Coordinates) (*ForecastData, error)

GetForecastByCoordinates returns the forecast by a given coordinates Sample: https://samples.openweathermap.org/data/2.5/forecast?lat=35&lon=139&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetForecastByZipCode

func (c *Client) GetForecastByZipCode(zipCode, countryCode string) (*ForecastData, error)

func (*Client) GetWeatherByCityID

func (c *Client) GetWeatherByCityID(cityID int64) (*WeatherData, error)

GetWeatherByCityID returns the weather in a given cityID Sample: https://samples.openweathermap.org/data/2.5/weather?id=2172797&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetWeatherByCityName

func (c *Client) GetWeatherByCityName(cityName string) (*WeatherData, error)

GetWeatherByCityName returns the weather in a given city Sample: https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetWeatherByCoordinates

func (c *Client) GetWeatherByCoordinates(coords Coordinates) (*WeatherData, error)

GetWeatherByCoordinates returns the weather by a given coordinates Sample: https://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=b6907d289e10d714a6e88b30761fae22

func (*Client) GetWeatherByZipCode

func (c *Client) GetWeatherByZipCode(zipCode, countryCode string) (*WeatherData, error)

GetWeatherByZipCode returns the weather by a given zip code and country code. If `countryCode` is not specified, it defaults to 'US', see: https://openweathermap.org/current#zip Sample: https://samples.openweathermap.org/data/2.5/weather?zip=94040,us&appid=b6907d289e10d714a6e88b30761fae22

type Coordinates

type Coordinates struct {
	Latitude  float64
	Longitude float64
}

Coordinates defines the cordinates of a place

type DailyForecastData

type DailyForecastData struct {
	Cod     string  `json:"cod"`
	Message float64 `json:"message"`
	City    struct {
		GeonameID  int     `json:"geoname_id"`
		Name       string  `json:"name"`
		Lat        float64 `json:"lat"`
		Lon        float64 `json:"lon"`
		Country    string  `json:"country"`
		Iso2       string  `json:"iso2"`
		Type       string  `json:"type"`
		Population int     `json:"population"`
	} `json:"city"`
	Cnt  int `json:"cnt"`
	List []struct {
		Dt   int `json:"dt"`
		Temp struct {
			Day   float64 `json:"day"`
			Min   float64 `json:"min"`
			Max   float64 `json:"max"`
			Night float64 `json:"night"`
			Eve   float64 `json:"eve"`
			Morn  float64 `json:"morn"`
		} `json:"temp"`
		Pressure float64 `json:"pressure"`
		Humidity int     `json:"humidity"`
		Weather  []struct {
			ID          int    `json:"id"`
			Main        string `json:"main"`
			Description string `json:"description"`
			Icon        string `json:"icon"`
		} `json:"weather"`
		Speed  float64 `json:"speed"`
		Deg    int     `json:"deg"`
		Clouds int     `json:"clouds"`
		Snow   float64 `json:"snow,omitempty"`
	} `json:"list"`
}

type ForecastData

type ForecastData struct {
	Cod     string  `json:"cod"`
	Message float64 `json:"message"`
	Cnt     int     `json:"cnt"`
	List    []struct {
		Dt   int `json:"dt"`
		Main struct {
			Temp      float64 `json:"temp"`
			TempMin   float64 `json:"temp_min"`
			TempMax   float64 `json:"temp_max"`
			Pressure  float64 `json:"pressure"`
			SeaLevel  float64 `json:"sea_level"`
			GrndLevel float64 `json:"grnd_level"`
			Humidity  int     `json:"humidity"`
			TempKf    float64 `json:"temp_kf"`
		} `json:"main"`
		Weather []struct {
			ID          int    `json:"id"`
			Main        string `json:"main"`
			Description string `json:"description"`
			Icon        string `json:"icon"`
		} `json:"weather"`
		Clouds struct {
			All int `json:"all"`
		} `json:"clouds"`
		Wind struct {
			Speed float64 `json:"speed"`
			Deg   float64 `json:"deg"`
		} `json:"wind"`
		Sys struct {
			Pod string `json:"pod"`
		} `json:"sys"`
		DtTxt string `json:"dt_txt"`
		Rain  struct {
			ThreeH float64 `json:"3h"`
		} `json:"rain,omitempty"`
		Snow struct {
			ThreeH float64 `json:"3h"`
		} `json:"snow,omitempty"`
	} `json:"list"`
	City struct {
		ID    int    `json:"id"`
		Name  string `json:"name"`
		Coord struct {
			Lat float64 `json:"lat"`
			Lon float64 `json:"lon"`
		} `json:"coord"`
		Country string `json:"country"`
	} `json:"city"`
}

ForecastData represents the forecast data from openweather

type WeatherData

type WeatherData struct {
	Coord struct {
		Lon float64 `json:"lon"`
		Lat float64 `json:"lat"`
	} `json:"coord"`
	Weather []struct {
		ID          int    `json:"id"`
		Main        string `json:"main"`
		Description string `json:"description"`
		Icon        string `json:"icon"`
	} `json:"weather"`
	Base string `json:"base"`
	Main struct {
		Temp      float64 `json:"temp"`
		Pressure  float64 `json:"pressure"`
		Humidity  int     `json:"humidity"`
		TempMin   float64 `json:"temp_min"`
		TempMax   float64 `json:"temp_max"`
		SeaLevel  float64 `json:"sea_level"`
		GrndLevel float64 `json:"grnd_level"`
	} `json:"main"`
	Wind struct {
		Speed float64 `json:"speed"`
		Deg   float64 `json:"deg"`
	} `json:"wind"`
	Clouds struct {
		All int `json:"all"`
	} `json:"clouds"`
	Dt  int `json:"dt"`
	Sys struct {
		Message float64 `json:"message"`
		Country string  `json:"country"`
		Sunrise int     `json:"sunrise"`
		Sunset  int     `json:"sunset"`
	} `json:"sys"`
	ID   int    `json:"id"`
	Name string `json:"name"`
	Cod  int    `json:"cod"`
}

WeatherData represents the weather information given by a certain parameters

Jump to

Keyboard shortcuts

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