diff options
author | Emile <hanemile@protonmail.com> | 2020-01-29 20:12:02 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2020-01-29 20:12:02 +0100 |
commit | a287863799656c91747530f247259911b2e698bc (patch) | |
tree | c6787f58731ec8b87c9fd8d1e3578106d2282558 /src | |
parent | 6e4affd636831e6af172b765459a2ac9fd4bf5ff (diff) |
setup the http server in http.go
Diffstat (limited to 'src')
-rw-r--r-- | src/http.go | 23 |
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 |