diff --git a/config.go b/config.go new file mode 100644 index 0000000..f2efa6c --- /dev/null +++ b/config.go @@ -0,0 +1,22 @@ +package main + +import ( + "github.com/BurntSushi/toml" + "os" +) + +type Config struct { + Quays []Quay +} + +func ReadConfigFromFile(filename string) (Config, error) { + var conf Config + + contents, err := os.ReadFile(filename) + if err != nil { + return conf, err + } + + _, err = toml.Decode(string(contents), &conf) + return conf, err +} diff --git a/go.mod b/go.mod index 71fa82f..3f36bb6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.jasperbok.nl/jasperbok/busdepartures.git go 1.20 + +require github.com/BurntSushi/toml v1.3.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ef0f966 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= diff --git a/quay.go b/quay.go index ab1fbe6..fb83604 100644 --- a/quay.go +++ b/quay.go @@ -6,10 +6,10 @@ import ( ) type Quay struct { - ID string `json:"quayid"` - Name string `json:"name"` - Town string `json:"town"` - RoutesOfInterest []Route + ID string `json:"quayid" toml:"id"` + Name string `json:"name" toml:"name"` + Town string `json:"town" toml:"town"` + RoutesOfInterest []Route `toml:"routes_of_interest"` } func (q Quay) IsInterestingDeparture(d Departure) bool { diff --git a/route.go b/route.go index 02bfe91..967dbe3 100644 --- a/route.go +++ b/route.go @@ -1,6 +1,6 @@ package main type Route struct { - RouteShortName string `json:"route_short_name"` - RouteLongName string `json:"route_long_name"` + RouteShortName string `json:"route_short_name" toml:"short_name"` + RouteLongName string `json:"route_long_name" toml:"long_name"` }