summaryrefslogtreecommitdiff
path: root/weather.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-02-05 13:46:40 +0000
committerNick White <git@njw.name>2021-02-05 13:46:40 +0000
commit8cfb6dbbf6ea6cea1e90f49b005d504d91d48894 (patch)
tree112ec1b2ad8e49e6c2311ae5fb432d91c3655fe8 /weather.go
parent3413df247aee70fc9ba217dfaa24bb217fff4248 (diff)
downloadweather-8cfb6dbbf6ea6cea1e90f49b005d504d91d48894.tar.bz2
weather-8cfb6dbbf6ea6cea1e90f49b005d504d91d48894.zip
Clean up parsing a little
Diffstat (limited to 'weather.go')
-rw-r--r--weather.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/weather.go b/weather.go
index b0ca2da..961b418 100644
--- a/weather.go
+++ b/weather.go
@@ -204,6 +204,7 @@ func main() {
var err error
var id string
var url string
+ var parsefunc func([]byte) []Weather
var resp *http.Response
var weather []Weather
@@ -213,9 +214,11 @@ func main() {
case "bbc":
id = bbcdefid
url = bbcurl
+ parsefunc = processBBC
case "metoffice":
id = metdefid
url = meturl
+ parsefunc = processMet
default:
log.Fatalf("data source %s not supported; use either 'bbc' or 'metoffice'\n", *src)
}
@@ -234,11 +237,7 @@ func main() {
}
b, err := ioutil.ReadAll(resp.Body)
- if *src == "bbc" {
- weather = processBBC(b)
- } else {
- weather = processMet(b)
- }
+ weather = parsefunc(b)
for _, w := range weather {
fmt.Printf("%s %s ", w.date, w.time)