From 8cfb6dbbf6ea6cea1e90f49b005d504d91d48894 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 5 Feb 2021 13:46:40 +0000 Subject: Clean up parsing a little --- weather.go | 9 ++++----- 1 file 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) -- cgit v1.2.3