mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-03-03 18:40:21 +00:00
added version endpoint
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/stefanprodan/k8s-podinfo/pkg/version"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@@ -52,6 +53,30 @@ func (s *Server) echo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) version(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/version" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
resp := map[string]string{
|
||||
"version": version.VERSION,
|
||||
"commit": version.GITCOMMIT,
|
||||
}
|
||||
|
||||
d, err := yaml.Marshal(resp)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/x-yaml; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(d)
|
||||
}
|
||||
|
||||
func (s *Server) healthz(w http.ResponseWriter, r *http.Request) {
|
||||
if atomic.LoadInt32(&healthy) == 1 {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
@@ -34,6 +34,7 @@ func NewServer(options ...func(*Server)) *Server {
|
||||
s.mux.HandleFunc("/readyz/disable", s.disable)
|
||||
s.mux.HandleFunc("/echo", s.echo)
|
||||
s.mux.HandleFunc("/panic", s.panic)
|
||||
s.mux.HandleFunc("/version", s.version)
|
||||
s.mux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return s
|
||||
|
||||
Reference in New Issue
Block a user