types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package types contains all the types associated to the goweather library : weather conditions, cities... Structures are not meant to be initialized by the user itself but only by the writer when editing the library.

Index

Constants

View Source
const APIURL = "https://api.openweathermap.org"

APIURL contains the address of the OpenWeatherMap API

Variables

View Source
var ConditionEmojis = map[string]rune{
	"01d": '☀',
	"02d": '⛅',
	"03d": '☁',
	"04d": '☁',
	"09d": '🌧',
	"10d": '🌦',
	"11d": '🌩',
	"13d": '🌨',
	"50d": '🌫',
}

ConditionEmojis contains OpenWeatherMap condition codes translated in emojis

View Source
var Endpoints = map[string]string{
	"current":  APIURL + "/data/2.5/weather",
	"forecast": APIURL + "/data/2.5/forecast",
}

Endpoints contains available endpoints through the API

View Source
var Locales = []string{"ar", "bg", "ca", "cz", "de", "el", "fa", "fi", "fr", "gl", "hr", "hu",
	"it", "ja", "kr", "la", "lt", "mk", "nl", "pl", "pt", "ro", "ru", "se", "sk", "sl", "es", "tr",
	"ua", "vi", "zh_cn", "zh_tw", "en"}

Locales contains accepted locales in the API

View Source
var Units = []string{"default", "metric", "imperial"}

Units contains accepted units in the API

Functions

This section is empty.

Types

type City

type City struct {
	// The name of the city, e.g "Lyon"
	Name string
	// Country code of the city, e.g "FR"
	Country string
	// The timestamp at which the sun rises
	Sunrise float64
	// The timestamp at which the sun sets
	Sunset float64
	// Coordinates of the city
	Coordinates Coordinates
}

City represents a real city and its data

type Coordinates

type Coordinates struct {
	Longitude float64
	Latitude  float64
}

Coordinates represents geographic coordinates of a specific location

type Current

type Current struct {
	// The city where the weather applies
	City City
	// The actual weather conditions at the moment
	Conditions WeatherConditions
}

Current represents current weather data

func (*Current) UnmarshalJSON

func (current *Current) UnmarshalJSON(raw []byte) (err error)

UnmarshalJSON parses data returned from the API into the structure

type Forecast

type Forecast struct {
	// The city where the weather applies
	City City
	// A list of all the weather conditions that will apply in the near future
	Conditions []WeatherConditions
}

Forecast represents weather forecast

func (*Forecast) UnmarshalJSON

func (forecast *Forecast) UnmarshalJSON(raw []byte) (err error)

UnmarshalJSON parses data returned from the API into the structure

type WeatherConditions

type WeatherConditions struct {
	// Timestamp at which the conditions occur
	Timestamp float64
	// Group of the conditions (Rain, snow, clouds...)
	Name string
	// Full description of the conditions
	Description string
	// URL to the PNG icon
	IconURL string
	// Emoji associated to the condition
	Emoji rune

	// Temperature at the location
	Temperature float64
	// Minimum temperature that can be felt
	MinimumTemperature float64
	// Maximum temperature that can be felt
	MaximumTemperature float64
	// Pressure at the location
	Pressure float64
	// Humidity at the location (percentage)
	Humidity float64

	// CLouds level (percentage)
	Clouds float64
	// Wind speed
	WindSpeed float64
}

WeatherConditions represents weather conditions at a specific moment

func ParseWeatherConditions

func ParseWeatherConditions(data map[string]interface{}) WeatherConditions

ParseWeatherConditions returns weather conditions parsed in a structure

Jump to

Keyboard shortcuts

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