summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-06-07 23:25:07 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-06-07 23:25:07 -0400
commit2ac5b96ce7df6f3a6b6e90dc667f0a9d59e138d9 (patch)
treee9078d9498038adf8ecab27bf74fb79bf4d6d039
parent1f15e5fd836ed6ce398891aa215a1020b9f82044 (diff)
nws: `CacheWeather` -> `GetForecastBundle`
-rw-r--r--nws/nws.go42
-rw-r--r--photon/photon.go2
-rw-r--r--version/version.go2
3 files changed, 40 insertions, 6 deletions
diff --git a/nws/nws.go b/nws/nws.go
index 42317ac..c6940d0 100644
--- a/nws/nws.go
+++ b/nws/nws.go
@@ -66,6 +66,13 @@ type Error struct {
Detail string
}
+// NWS Forecast bundle.
+type ForecastBundle struct {
+ Point *Point
+ Forecast *Forecast
+ ForecastHourly *Forecast
+}
+
var pCache *cache.Cache
var fCache *cache.Cache
var fhCache *cache.Cache
@@ -80,13 +87,40 @@ func (e Error) Error() string {
return fmt.Sprintf("%d: %s: %s", e.Status, e.Type, e.Detail)
}
-func CacheWeather(lat, lng float32) {
+// Gets NWS's forecast and hourly forecast.
+func GetForecastBundle(lat, lng float32) (*ForecastBundle, *Error) {
p, err := Points(lat, lng)
if err != nil {
- return
+ return nil, &Error{
+ Title: "unable get points",
+ Type: "points-failed",
+ Status: 500,
+ Detail: err.Error(),
+ }
+ }
+ f, err := GetForecast(p)
+ if err != nil {
+ return nil, &Error{
+ Title: "unable get forecast",
+ Type: "forecast-failed",
+ Status: 500,
+ Detail: err.Error(),
+ }
+ }
+ fh, err := GetForecastHourly(p)
+ if err != nil {
+ return nil, &Error{
+ Title: "unable get hourly forecast",
+ Type: "forecast-hourly-failed",
+ Status: 500,
+ Detail: err.Error(),
+ }
}
- GetForecast(p)
- GetForecastHourly(p)
+ return &ForecastBundle{
+ Point: p,
+ Forecast: f,
+ ForecastHourly: fh,
+ }, nil
}
// NWS `/points` endpoint.
diff --git a/photon/photon.go b/photon/photon.go
index d75d369..3051db3 100644
--- a/photon/photon.go
+++ b/photon/photon.go
@@ -131,7 +131,7 @@ func Geocode(location string) ([]Coordinates, error) {
names[c.Name] = true
mCoords = append(mCoords, c)
- go nws.CacheWeather(c.Lat, c.Lng)
+ go nws.GetForecastBundle(c.Lat, c.Lng)
}
return mCoords, nil
}
diff --git a/version/version.go b/version/version.go
index 0d2fcc2..6f50529 100644
--- a/version/version.go
+++ b/version/version.go
@@ -4,4 +4,4 @@
// Peach version.
package version
-const Version = "0.4.1"
+const Version = "0.4.2.dev"