Implement health check for deploy. Make version endpoint to return revision if not set
This commit is contained in:
@@ -3,6 +3,7 @@ package version
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
@@ -39,7 +40,20 @@ type handler struct {
|
||||
func (h *handler) VersionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
|
||||
ver := h.version
|
||||
if ver == "unknown" {
|
||||
buildInfo, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
for _, setting := range buildInfo.Settings {
|
||||
if setting.Key == "vcs.revision" {
|
||||
ver = ver + "-" + setting.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
io.WriteString(w, h.version)
|
||||
io.WriteString(w, ver+"\n")
|
||||
}
|
||||
Reference in New Issue
Block a user