about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--main.go45
-rw-r--r--structs.go25
2 files changed, 35 insertions, 35 deletions
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
+}
diff --git a/structs.go b/structs.go
new file mode 100644
index 0000000..8b53fe9
--- /dev/null
+++ b/structs.go
@@ -0,0 +1,25 @@
+package main
+
+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"`
+}