veterejo

package module
v0.0.0-...-31802b3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Go Report Card

veterejo

Veterejo is a Go package for querying weather data from Open Weather Maps.

Vetero is "weather" in Esperanto and "ejo" is place. By replacing the o of a noun with ejo the word discribes a place of that thing. (eg: Computilejo = computer-place or in English a computer lab)

Using This Package:

  1. Get an API Key from OpenWeatheMap
  2. Import this package
  3. Create a new WeatherData struct: w := new(veterejo.WeatherData)
  4. Parse the URL: url, err := veterejo.MakeURL(yourCityID, unitsOfMeasure, yourApiId)
    • yourApiId is required
    • The rest may be omitted by passing an empty string.
    • This package defaults the units of mesaure to metric.
  5. Call the data: w.getData(url)
  6. Use the appropriate method to get the most recent data needed from OpenWeatherMap.

veterejo is licensed under the BSD 3-Clause "New" or "Revised" License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeURL

func MakeURL(cityID, units, apiID string) (string, error)

MakeURL formats the URL for the Open Weather Map API call

Types

type WeatherData

type WeatherData struct {
	Coord struct {
		Lon float32 `json:"lon"`
		Lat float32 `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      float32 `json:"temp"`
		FeelsLike float32 `json:"feels_like"`
		TempMin   float32 `json:"temp_min"`
		TempMax   int     `json:"temp_max"`
		Pressure  int     `json:"pressure"`
		Humidity  int     `json:"humidity"`
	} `json:"main"`
	Visibility int `json:"visibility"`
	Wind       struct {
		Speed float32 `json:"speed"`
		Deg   int     `json:"deg"`
	} `json:"wind"`
	Clouds struct {
		All int `json:"all"`
	} `json:"clouds"`
	Dt  int `json:"dt"`
	Sys struct {
		Type    int    `json:"type"`
		ID      int    `json:"id"`
		Country string `json:"country"`
		Sunrise int    `json:"sunrise"`
		Sunset  int    `json:"sunset"`
	} `json:"sys"`
	Timezone int    `json:"timezone"`
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Cod      int    `json:"cod"`
}

WeatherData holds the information passed back from the OpenWeather API

func (*WeatherData) GetCloudCoverage

func (w *WeatherData) GetCloudCoverage() int

GetCloudCoverage returns an int as a percentage of cloud coverage

func (*WeatherData) GetCoords

func (w *WeatherData) GetCoords() string

GetCoords returns a string of "lat, long"

func (*WeatherData) GetData

func (w *WeatherData) GetData(url string) error

GetData calls the OpenWeatherMap API and adds the date to the struct.

func (*WeatherData) GetFeelsLike

func (w *WeatherData) GetFeelsLike() float32

GetFeelsLike returns the current "feels like" temperature that GetData gets in the call.

func (*WeatherData) GetHumidity

func (w *WeatherData) GetHumidity() int

GetHumidity returns the current humidity (as a percentage) that GetData gets in the call.

func (*WeatherData) GetMaxTemp

func (w *WeatherData) GetMaxTemp() int

GetMaxTemp returns the current high temperature that GetData gets in the call.

func (*WeatherData) GetMinTemp

func (w *WeatherData) GetMinTemp() float32

GetMinTemp returns the current high temperature that GetData gets in the call.

func (*WeatherData) GetPressure

func (w *WeatherData) GetPressure() int

GetPressure returns the current pressure that GetData gets in the call.

func (*WeatherData) GetTemp

func (w *WeatherData) GetTemp() float32

GetTemp returns the current temperature that GetData gets in the call.

func (*WeatherData) GetVisibility

func (w *WeatherData) GetVisibility() int

GetVisibility returns a visiblity meter integer

func (*WeatherData) GetWindSpeed

func (w *WeatherData) GetWindSpeed() float32

GetWindSpeed returns the current windspeed of the city.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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