mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add enviroment, commit and commit link to status page
This commit is contained in:
parent
3491d88251
commit
78a0163928
2 changed files with 32 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue