weather

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package weather provides current weather conditions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvgAQI added in v0.4.0

func AvgAQI(
	getter AQIGetter,
	delayBetweenCalls time.Duration,
	stationIds ...int64) (aqi int, err error)

AvgAQI returns the average AQI index over multiple stations rounded to the nearest whole number. delayBetweenCalls is the time delay between calls to get the AQI of each station. If getting the AQI for a station returns an error, that station is omitted from the average AQI returned. If AvgAQI is unable to get an AQI from any of the stations, it returns the last error encountered. AvgAQI panics if no stationIds are passed to it.

Types

type AQIGetter added in v0.4.0

type AQIGetter interface {
	GetAQI(stationId int64) (aqi int, err error)
}

PurpleAirConn implements this interface.

type Cache

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

Cache stores a single weather observation and notifies clients when this observation changes. Cache instances can be safely used with multiple goroutines.

func NewCache

func NewCache() *Cache

NewCache creates a new cache containing no observation.

func (*Cache) Close

func (c *Cache) Close() error

Close frees resources associated with this cache.

func (*Cache) Get

func (c *Cache) Get() (*Observation, <-chan struct{})

Get returns the current observation in this cache. Clients can use the returned channel to block until a new observation is available.

func (*Cache) Set

func (c *Cache) Set(observation *Observation)

Set updates the observation in this cache and notifies all waiting clients.

type Observation

type Observation struct {
	// Temperature in celsius
	Temperature float64 `xml:"temp_c"`
	// Weather conditions e.g 'Fair' or 'Partly Cloudy'
	Weather string `xml:"weather"`
}

Observation represents a weather observation. These instances must be treated as immutable.

func Get

func Get(station string) (observation *Observation, err error)

Get returns the current observation from a NOAA weather station. For example "KNUQ" means moffett field.

type OpenWeatherConn

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

OpenWeatherConn represents a connection to the open weather servers

func NewOpenWeatherConn

func NewOpenWeatherConn(apiKey string) *OpenWeatherConn

NewOpenWeatherConn returns a new, long lived, open weather connection.

func (*OpenWeatherConn) Get

func (c *OpenWeatherConn) Get(cityId string) (
	observation *Observation, err error)

Get returns the weather for a particular city. The city ID for a city can be found by downloading city.list.json.gz from http://bulk.openweathermap.org/sample/. For example, Mountain View, CA is "5375480"

type PurpleAirConn

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

PurpleAirConn represents a connection to purple air

func NewPurpleAirConn

func NewPurpleAirConn(apiKey string) *PurpleAirConn

NewPurpleAirConn returns a new, long lived, purple air connection.

func (*PurpleAirConn) GetAQI

func (p *PurpleAirConn) GetAQI(stationId int64) (aqi int, err error)

GetAQI returns the AQI for a particular purple air station.

type Report

type Report struct {
	// Temperature in celsius
	Temperature float64

	// Weather conditions e.g 'Fair' or 'Partly Cloudy'
	Condition string

	// The Air Quality Index (0-500)
	AQI int
}

Report represents a weather report which may include readings from multiple services.

type ReportCache

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

ReportCache stores a single weather report and notifies clients when this report changes. ReportCache instances can be safely used with multiple goroutines.

func NewReportCache

func NewReportCache() *ReportCache

NewReportCache creates a new report cache containing a zero value report.

func (*ReportCache) Close

func (r *ReportCache) Close() error

Close frees resources associated with this report cache.

func (*ReportCache) Get

func (r *ReportCache) Get(result *Report) <-chan struct{}

Get stores the current report at result. Clients can use the returned channel to block until a new report is available.

func (*ReportCache) Set

func (r *ReportCache) Set(report *Report)

Set updates the report in this report cache and notifies all waiting clients.

Jump to

Keyboard shortcuts

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