From 8df1ac94b5003b672066c9485d0aaa0eeca3d1c4 Mon Sep 17 00:00:00 2001 From: Jasper Bok Date: Sun, 20 Aug 2023 19:37:41 +0200 Subject: [PATCH] Move `Quay` and `Route` to their own files --- main.go | 29 ----------------------------- quay.go | 28 ++++++++++++++++++++++++++++ route.go | 6 ++++++ 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 quay.go create mode 100644 route.go diff --git a/main.go b/main.go index a53f672..4c1cb55 100644 --- a/main.go +++ b/main.go @@ -2,38 +2,9 @@ package main import ( "flag" - "fmt" "net/http" - "net/url" ) -type Route struct { - RouteShortName string `json:"route_short_name"` - RouteLongName string `json:"route_long_name"` -} - -type Quay struct { - ID string `json:"quayid"` - Name string `json:"name"` - Town string `json:"town"` - RoutesOfInterest []Route -} - -func (q Quay) IsInterestingDeparture(d Departure) bool { - for _, route := range q.RoutesOfInterest { - if (route.RouteShortName == d.RouteShortName) && (route.RouteLongName == d.StopHeadsign) { - return true - } - } - - return false -} - -func (q Quay) GetBrengUrl() string { - param := fmt.Sprintf("{\"quayid\":\"%s\",\"name\":\"%s\",\"town\":\"%s\"}", q.ID, q.Name, q.Town) - return fmt.Sprint("https://www.breng.nl/nl/resultaten/halte-informatie/?stop=%s", url.QueryEscape(param)) -} - var BusClient *http.Client var Quays []Quay = []Quay{} diff --git a/quay.go b/quay.go new file mode 100644 index 0000000..ab1fbe6 --- /dev/null +++ b/quay.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "net/url" +) + +type Quay struct { + ID string `json:"quayid"` + Name string `json:"name"` + Town string `json:"town"` + RoutesOfInterest []Route +} + +func (q Quay) IsInterestingDeparture(d Departure) bool { + for _, route := range q.RoutesOfInterest { + if (route.RouteShortName == d.RouteShortName) && (route.RouteLongName == d.StopHeadsign) { + return true + } + } + + return false +} + +func (q Quay) GetBrengUrl() string { + param := fmt.Sprintf("{\"quayid\":\"%s\",\"name\":\"%s\",\"town\":\"%s\"}", q.ID, q.Name, q.Town) + return fmt.Sprintf("https://www.breng.nl/nl/resultaten/halte-informatie/?stop=%s", url.QueryEscape(param)) +} diff --git a/route.go b/route.go new file mode 100644 index 0000000..02bfe91 --- /dev/null +++ b/route.go @@ -0,0 +1,6 @@ +package main + +type Route struct { + RouteShortName string `json:"route_short_name"` + RouteLongName string `json:"route_long_name"` +}