From 7be2a6d747a767d016b976de60ce2bb21d3a5203 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 27 Jan 2020 20:12:24 +0100 Subject: moved structs into an own file --- main.go | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ee3938e..74f8f51 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,11 @@ package main import ( - "encoding/json" - "fmt" - "github.com/gliderlabs/ssh" - //"github.com/gorilla/mux" - "io/ioutil" "log" "net/http" - "strings" + + "github.com/gliderlabs/ssh" + "github.com/gorilla/mux" ) var ( @@ -17,30 +14,6 @@ var ( cities map[string]location ) -type geoipresult struct { - Query string `json:"query"` - Status string `json:"status"` - Country string `json:"country"` - CountryCode string `json:"countryCode"` - Region string `json:"region"` - RegionName string `json:"regionName"` - City string `json:"city"` - Zip string `json:"zip"` - Lat float64 `json:"lat"` - Lon float64 `json:"lon"` - Timezone string `json:"timezone"` - Isp string `json:"isp"` - Org string `json:"org"` - As string `json:"as"` -} - -type location struct { - key string `json:"key"` - latitude float64 `json:"latitude"` - longitude float64 `json:"longitude"` - name string `json:"name"` -} - func main() { // create a map mapping a city to an amount of hits @@ -60,15 +33,17 @@ func main() { // start the http server logging the metrics log.Println("Starting HTTP metrics listener") - http.HandleFunc("/", indexHandler) - http.HandleFunc("/metrics", metricsHandler) - http.HandleFunc("/locations", locationHandlerEndpoint) + + r := mux.NewRouter() + r.HandleFunc("/", indexHandler) + r.HandleFunc("/metrics", metricsHandler) + r.HandleFunc("/locations", locationHandlerEndpoint) // start the http server exposing the metrics and the locations - listenErr := http.ListenAndServe(":8084", nil) + listenErr := http.ListenAndServe(":8084", r) // handle potential errors if listenErr != nil { log.Fatalln(listenErr.Error()) } -} \ No newline at end of file +} -- cgit 1.4.1