change http router to gorilla/mux

This commit is contained in:
Andre Kully 2021-12-23 16:54:45 +01:00
parent 7c2157ff53
commit 5aeb0808da
4 changed files with 6 additions and 2 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
mystrom-exporter mystrom-exporter
output/* output/*
*_string.go
# Created by https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows # Created by https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,intellij+all,windows # Edit at https://www.toptal.com/developers/gitignore?templates=osx,intellij+all,windows
@ -148,4 +149,4 @@ $RECYCLE.BIN/
# Windows shortcuts # Windows shortcuts
*.lnk *.lnk
# End of https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows # End of https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows

1
go.mod
View file

@ -3,6 +3,7 @@ module mystrom-exporter
go 1.15 go 1.15
require ( require (
github.com/gorilla/mux v1.7.3
github.com/prometheus/client_golang v1.10.0 github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.18.0 github.com/prometheus/common v0.18.0
) )

1
go.sum
View file

@ -99,6 +99,7 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=

View file

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
@ -69,7 +70,7 @@ func main() {
// -- create a new registry for the exporter telemetry // -- create a new registry for the exporter telemetry
telemetryRegistry := setupMetrics() telemetryRegistry := setupMetrics()
router := http.NewServeMux() router := mux.NewRouter()
router.Handle(*metricsPath, promhttp.HandlerFor(telemetryRegistry, promhttp.HandlerOpts{})) router.Handle(*metricsPath, promhttp.HandlerFor(telemetryRegistry, promhttp.HandlerOpts{}))
router.HandleFunc(*devicePath, scrapeHandler) router.HandleFunc(*devicePath, scrapeHandler)
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {