weather

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 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

This section is empty.

Types

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 added in v1.1.0

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

PurpleAirConn represents a connection to purple air

func NewPurpleAirConn added in v1.1.0

func NewPurpleAirConn() *PurpleAirConn

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

func (*PurpleAirConn) GetAQI added in v1.1.0

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

GetAQI returns the AQI for a particular purple air station.

type Report added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

func NewReportCache() *ReportCache

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

func (*ReportCache) Close added in v1.1.0

func (r *ReportCache) Close() error

Close frees resources associated with this report cache.

func (*ReportCache) Get added in v1.1.0

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

Get returns a shallow copy of the current report. Clients can use the returned channel to block until a new report is available.

func (*ReportCache) Set added in v1.1.0

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