about summary refs log tree commit diff
path: root/main.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2020-01-27 20:12:24 +0100
committerEmile <hanemile@protonmail.com>2020-01-27 20:12:24 +0100
commit7be2a6d747a767d016b976de60ce2bb21d3a5203 (patch)
treeec4d309ec0b3c584d82278c3536d79d80eda52f5 /main.go
parent14f1a07678995cc754ddb39dadc0071ce21e48ea (diff)
moved structs into an own file
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 10 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
+}