about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/http.go b/src/http.go
index 47f0d75..1ff432b 100644
--- a/src/http.go
+++ b/src/http.go
@@ -2,10 +2,33 @@ package main
 
 import (
 	"fmt"
+	"log"
 	"net/http"
 	"strings"
+
+	"github.com/gorilla/mux"
 )
 
+func setupHTTPServer(config config) {
+
+	// start the http server logging the metrics
+	log.Printf("Starting HTTP metrics listener on port %d", config.httpPort)
+
+	r := mux.NewRouter()
+	r.HandleFunc("/", indexHandler)
+	r.HandleFunc("/metrics", metricsHandler)
+	r.HandleFunc("/locations", locationHandlerEndpoint)
+
+	// start the http server exposing the metrics and the locations
+	httpPortString := fmt.Sprintf("%s:%d", config.bindIP, config.httpPort)
+	listenErr := http.ListenAndServe(httpPortString, r)
+
+	// handle potential errors
+	if listenErr != nil {
+		log.Fatalln(listenErr.Error())
+	}
+}
+
 // locationHandlerEndpoint handles requests to the /locations endpoint
 // This is used by the grafana worldmap plugin to find out where to draw the
 // fancy circles