add enviroment, commit and commit link to status page

This commit is contained in:
lyx0 2023-12-10 21:04:59 +01:00
parent 3491d88251
commit 78a0163928
2 changed files with 32 additions and 3 deletions

View file

@ -6,15 +6,15 @@ import (
"net/http"
"github.com/lyx0/nourybot/internal/common"
"github.com/lyx0/nourybot/pkg/humanize"
)
func (app *application) statusPage() {
commit := common.GetVersion()
botUptime := humanize.Time(common.GetUptime())
started := common.GetUptime().Format("2006-1-2 15:4:5")
commitLink := fmt.Sprintf("https://github.com/lyx0/nourybot/commit/%v", common.GetVersionPure())
statusHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, fmt.Sprintf("up\nlast restart: %v\nenv: %v\ncommit: %v", botUptime, app.Environment, commit))
io.WriteString(w, fmt.Sprintf("started: \t%v\nenvironment: \t%v\ncommit: \t%v\ngithub: \t%v", started, app.Environment, commit, commitLink))
}
http.HandleFunc("/status", statusHandler)

View file

@ -39,3 +39,32 @@ func GetVersion() string {
return revision
}
func GetVersionPure() string {
var revision string
var modified bool
bi, ok := debug.ReadBuildInfo()
if ok {
for _, s := range bi.Settings {
switch s.Key {
case "vcs.revision":
revision = s.Value
case "vcs.modified":
if s.Value == "true" {
modified = true
}
}
}
}
if revision == "" {
return "unavailable"
}
if modified {
return fmt.Sprintf("%s", revision)
}
return revision
}