mirror of
https://github.com/steinhobelgruen/netatmo-exporter.git
synced 2024-12-21 20:13:57 +00:00
Add handler for version information
This commit is contained in:
parent
ee49657c75
commit
87960917f6
1
main.go
1
main.go
|
@ -41,6 +41,7 @@ func main() {
|
|||
prometheus.MustRegister(metrics)
|
||||
|
||||
http.Handle("/metrics", promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{}))
|
||||
http.Handle("/version", versionHandler(log))
|
||||
http.Handle("/", http.RedirectHandler("/metrics", http.StatusFound))
|
||||
|
||||
log.Infof("Listen on %s...", cfg.Addr)
|
||||
|
|
33
version.go
Normal file
33
version.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version contains the version as set during the build.
|
||||
Version = ""
|
||||
|
||||
// GitCommit contains the git commit hash set during the build.
|
||||
GitCommit = ""
|
||||
)
|
||||
|
||||
func versionHandler(log logrus.FieldLogger) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
info := struct {
|
||||
Version string `json:"version"`
|
||||
Commit string `json:"commit"`
|
||||
}{
|
||||
Version: Version,
|
||||
Commit: GitCommit,
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(info); err != nil {
|
||||
log.Errorf("Error encoding version info: %s", err)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue