Documentation ¶
Index ¶
Constants ¶
const ( // DefaultURL is default WAQI service root URL DefaultURL = "https://api.waqi.info/" // DefaultCacheDuration is default WAQI service cache duration DefaultCacheDuration = 15 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error string
Error represents a service-specific error
type Level ¶
type Level string
Level is an air quality level value
const ( // GoodLevel means air quality is considered satisfactory. // Maps to AQI from 0 to 50. GoodLevel Level = "good" // ModerateLevel means air quality is overall satisfactory // but there may be a moderate health concern for a very small number of people // who are unusually sensitive to air pollution // Maps to AQI from 51 to 100 ModerateLevel Level = "moderate" // PossiblyUnhealthyLevel means members of sensitive groups may experience health effects. // Maps to AQI from 101 to 150. PossiblyUnhealthyLevel = "possibly_unhealthy" // UnhealthyLevel means everyone may begin to experience health effects // and members of sensitive groups may experience more serious health effects // Maps to AQI from 151 to 200. UnhealthyLevel Level = "unhealthy" // VeryUnhealthyLevel is means health warnings of emergency conditions. // Maps to AQI from 201 to 300. VeryUnhealthyLevel Level = "very_unhealthy" // HazardousLevel means a health alert. // Maps to AQI from 300 and above. HazardousLevel Level = "hazardous" )
func CalcAQILevel ¶
CalcAQILevel calculates an air quality level for raw AQI value
func CalcCOLevel ¶
CalcCOLevel calculates a CO level for raw CO value
func CalcNO2Level ¶
CalcNO2Level calculates a NO2 level for raw NO2 value
func CalcO3Level ¶
CalcO3Level calculates an O3 level for raw O3 value
func CalcPM10Level ¶
CalcPM10Level calculates a PM10 level for raw PM10 value
func CalcPM25Level ¶
CalcPM25Level calculates a PM2.5 level for raw PM2.5 value
func CalcSO2Level ¶
CalcSO2Level calculates a SO2 level for raw SO2 value
type Listener ¶
type Listener interface { // Update handles a weather data update // prevStatus will be nil on first update // and not nil - on subsequent ones Update(status *Status, prevStatus *Status) error }
Listener receives updates on air quality status
type Option ¶
type Option func(*options)
Option is a configuration option for NewServer function
func CacheDurationOption ¶
CacheDurationOption sets max cache duration
func CachePathOption ¶
CachePathOption sets path to cache file
type Service ¶
type Service interface { // GetByCity fetches current measurements for city GetByCity(city string) (*Status, error) // GetByStation fetches current measurements for station GetByStation(stationID int) (*Status, error) // GetByGeo fetches current measurements for geo coordinates GetByGeo(lat, lon float32) (*Status, error) // Subscribe adds a listener to updates Subscribe(stationID int, listener Listener) // Unsubscribe removes a listener Unsubscribe(stationID int, listener Listener) // StartUpdates starts background data updates StartUpdates() // StopUpdates stops background data updates StopUpdates() // Close shuts down service Close() error }
Service is an entry point for WAQI service
func NewService ¶
NewService creates new instance of Service
type Station ¶
type Station struct { // Unique ID for the city monitoring station. ID int `json:"id"` // Name of the monitoring station Name string `json:"name"` // URL of the monitoring station website URL string `json:"url"` // Latitude of the monitoring station Lon float32 `json:"lon"` // Longitude of the monitoring station Lat float32 `json:"lat"` }
Station contains weather station information
type Status ¶
type Status struct { Station *Station `json:"station"` // Measurement time Time time.Time `json:"time"` // Air quality index value AQI float32 `json:"aqi"` // Air quality index level Level Level `json:"level"` // Particulate matter 2.5 measurement PM25 *float32 `json:"pm25"` // Particulate matter 10 measurement PM10 *float32 `json:"pm10"` // Ozone measurement O3 *float32 `json:"o3"` // Nitrogen dioxide measurement NO2 *float32 `json:"no2"` // Sulfur dioxide measurement SO2 *float32 `json:"so2"` // Carbon monoxide level measurement CO *float32 `json:"co"` }
Status contains aggregated air quality status