Documentation
¶
Index ¶
Constants ¶
const InvalidData = 9999
const ModuleVersion = "0.0.10"
Variables ¶
var YrAppHeader = "https://bitbucket.org/HelgeOlav/yr " + ModuleVersion // our app header, sent to Yr
Functions ¶
This section is empty.
Types ¶
type CompactTimeSeries ¶
type CompactTimeSeries struct {
Time time.Time `json:"time"`
Data struct {
Instant struct {
Details struct {
AirPressureAtSeaLevel float64 `json:"air_pressure_at_sea_level"`
AirTemperature float64 `json:"air_temperature"`
CloudAreaFraction float64 `json:"cloud_area_fraction"`
RelativeHumidity float64 `json:"relative_humidity"`
WindFromDirection float64 `json:"wind_from_direction"`
WindSpeed float64 `json:"wind_speed"`
} `json:"details"`
} `json:"instant"`
Next12Hours struct {
Summary struct {
SymbolCode string `json:"symbol_code"`
} `json:"summary"`
} `json:"next_12_hours,omitempty"`
Next1Hours struct {
Summary struct {
SymbolCode string `json:"symbol_code"`
} `json:"summary"`
Details struct {
PrecipitationAmount float64 `json:"precipitation_amount"`
} `json:"details"`
} `json:"next_1_hours,omitempty"`
Next6Hours struct {
Summary struct {
SymbolCode string `json:"symbol_code"`
} `json:"summary"`
Details struct {
PrecipitationAmount float64 `json:"precipitation_amount"`
} `json:"details"`
} `json:"next_6_hours,omitempty"`
} `json:"data"`
}
type Weather ¶
type Weather struct {
Result YrCompactData `json:"result"` // the data from Yr
IsValid bool `json:"isValid"` // if this result is valid
IsCached bool `json:"-"` // true if data was cached from file
Expires time.Time `json:"expires,omitempty"` // when the current data expires
Error string `json:"error,omitempty"` // any error
}
Weather is the internal data structure that is sent to clients
func (*Weather) GetCurrentTemperature ¶
GetCurrentTemperature returns the current temperature if the data is valid, otherwise InvalidData
type YrCompactData ¶
type YrCompactData struct {
Type string `json:"type"`
Geometry struct {
Type string `json:"type"`
Coordinates []float64 `json:"coordinates"`
} `json:"geometry"`
Properties struct {
Meta struct {
UpdatedAt time.Time `json:"updated_at"`
Units struct {
AirPressureAtSeaLevel string `json:"air_pressure_at_sea_level"`
AirTemperature string `json:"air_temperature"`
CloudAreaFraction string `json:"cloud_area_fraction"`
PrecipitationAmount string `json:"precipitation_amount"`
RelativeHumidity string `json:"relative_humidity"`
WindFromDirection string `json:"wind_from_direction"`
WindSpeed string `json:"wind_speed"`
} `json:"units"`
} `json:"meta"`
Timeseries []CompactTimeSeries `json:"timeseries"`
} `json:"properties"`
}
YrCompactData is the data returned from yr
type YrMicroServiceWebData ¶
type YrMicroServiceWebData struct {
Value utils.Broadcast[Weather] // the current data, as returned from Yr
// contains filtered or unexported fields
}
YrMicroServiceWebData is the data set when loaded from an internal microservice
func NewYrMicroServiceWebData ¶
func NewYrMicroServiceWebData(url string) *YrMicroServiceWebData
NewYrMicroServiceWebData returns a new instance where it is loading data from the origin server
func (*YrMicroServiceWebData) AutoUpdate ¶
func (y *YrMicroServiceWebData) AutoUpdate(ctx context.Context, interval time.Duration)
AutoUpdate is a long-lived thread that updates the data from the source at given intervals
func (*YrMicroServiceWebData) Update ¶
func (y *YrMicroServiceWebData) Update() error
Update retrieves data from the origin server, returning error if the update failed
type YrOriginWeatherData ¶
type YrOriginWeatherData struct {
Value utils.Broadcast[Weather] // the current data, as returned from Yr
// contains filtered or unexported fields
}
YrOriginWeatherData represents the exposed API for the weather data
func NewYrWeatherData ¶
func NewYrWeatherData(lat, lon float64, cacheFile string) *YrOriginWeatherData
NewYrWeatherData initializes the weather for a given place, caching data to a cacheFile
func (*YrOriginWeatherData) AutomaticUpdate ¶
func (y *YrOriginWeatherData) AutomaticUpdate(ctx context.Context)
AutomaticUpdate is a background task that will update the data each time it expires. Context is used to signal that updating should be stopped.
func (*YrOriginWeatherData) ServeHTTP ¶
func (y *YrOriginWeatherData) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is a handler that will return the current Weather as JSON data. It also implements the http.Handler interface.
func (*YrOriginWeatherData) UpdateWeather ¶
func (y *YrOriginWeatherData) UpdateWeather() error
UpdateWeather updates the weather if it is invalid or if the data has expired. error is always returned unless the data was updated.