From 5551263d6b096ee58ffb1aaf1a75b508a692e716 Mon Sep 17 00:00:00 2001 From: Adamarar Date: Sat, 17 Feb 2018 01:30:30 +0100 Subject: [PATCH] Cleanup and document code. --- README.md | 3 +++ Station.json | 14 ++++++++++++++ main.go | 9 +++------ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 Station.json diff --git a/README.md b/README.md index a0756fb..a63e7a8 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,6 @@ $ docker run -d -p 8080:8080 velo ## Contributing Send PR. + +## Disclaimer +I'm not a professional developer. diff --git a/Station.json b/Station.json new file mode 100644 index 0000000..dcdcb65 --- /dev/null +++ b/Station.json @@ -0,0 +1,14 @@ +[ + { + "id":"001", + "lon":"4.420650000000000000", + "lat":"51.217820000000000000", + "bikes":"0", + "slots":"31", + "zip":"2018", + "address":"Koningin Astridplein", + "status":"OPN", + "name":"001- Centraal Station - Astrid", + "stationType":"BIKE" + } +] diff --git a/main.go b/main.go index 6a574b3..d29aaaa 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func init() { } // Station holds all the data that a single station has. +// See Station.json for how the original looks like. type Station struct { ID string `json:"id"` District string `json:"-"` @@ -82,6 +83,7 @@ func (v *VeloManager) GetStations() (bikesByStation map[string]int, slotsByStati slots := Stations[idx].Slots name := Stations[idx].Name + // Convert json string to int. iBikes, err := strconv.Atoi(bike) if err != nil { log.Printf("Error strconv bike: %v", err) @@ -99,12 +101,6 @@ func (v *VeloManager) GetStations() (bikesByStation map[string]int, slotsByStati end := time.Now() log.Printf("Duration: %v", end.Sub(start)) - // bikesByStation["045-Falconplein"] = 12 - // bikesByStation["046-Somewhere"] = 14 - - // slotsByStation["045-Falconplain"] = 8 - // slotsByStation["046-Somewhere"] = 6 - return } @@ -162,6 +158,7 @@ func main() { flag.Parse() log.Printf("Pushing metrics on port: %v", *addr) + // Expose the registered metrics via HTTP. http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(*addr, nil))