Compare commits
No commits in common. "8826be46375219158ec4bb68379f2305ab593b87" and "8df1ac94b5003b672066c9485d0aaa0eeca3d1c4" have entirely different histories.
8826be4637
...
8df1ac94b5
22
config.go
22
config.go
|
@ -1,22 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
2
go.mod
2
go.mod
|
@ -1,5 +1,3 @@
|
||||||
module git.jasperbok.nl/jasperbok/busdepartures.git
|
module git.jasperbok.nl/jasperbok/busdepartures.git
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require github.com/BurntSushi/toml v1.3.2
|
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,2 +0,0 @@
|
||||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
|
||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
|
19
main.go
19
main.go
|
@ -2,35 +2,18 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var BusClient *http.Client
|
var BusClient *http.Client
|
||||||
var Quays []Quay
|
var Quays []Quay = []Quay{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var confFilename string
|
|
||||||
var port int
|
var port int
|
||||||
|
|
||||||
flag.StringVar(&confFilename, "c", "", "Path to the configuration file")
|
|
||||||
flag.IntVar(&port, "p", 4444, "The port to start the server on")
|
flag.IntVar(&port, "p", 4444, "The port to start the server on")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if confFilename == "" {
|
|
||||||
fmt.Printf("No configuation file provided. Provide the path to a configuration file with the -c flag.\n")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
conf, err := ReadConfigFromFile(confFilename)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
Quays = conf.Quays
|
|
||||||
|
|
||||||
BusClient = &http.Client{}
|
BusClient = &http.Client{}
|
||||||
serveHttp(port)
|
serveHttp(port)
|
||||||
}
|
}
|
||||||
|
|
8
quay.go
8
quay.go
|
@ -6,10 +6,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Quay struct {
|
type Quay struct {
|
||||||
ID string `json:"quayid" toml:"id"`
|
ID string `json:"quayid"`
|
||||||
Name string `json:"name" toml:"name"`
|
Name string `json:"name"`
|
||||||
Town string `json:"town" toml:"town"`
|
Town string `json:"town"`
|
||||||
RoutesOfInterest []Route `toml:"routes_of_interest"`
|
RoutesOfInterest []Route
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q Quay) IsInterestingDeparture(d Departure) bool {
|
func (q Quay) IsInterestingDeparture(d Departure) bool {
|
||||||
|
|
4
route.go
4
route.go
|
@ -1,6 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type Route struct {
|
type Route struct {
|
||||||
RouteShortName string `json:"route_short_name" toml:"short_name"`
|
RouteShortName string `json:"route_short_name"`
|
||||||
RouteLongName string `json:"route_long_name" toml:"long_name"`
|
RouteLongName string `json:"route_long_name"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue