mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
unify buildinfo in a single file. fix /status page not working
This commit is contained in:
parent
a44cab6b3f
commit
bfae6bb73f
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/nicklaw5/helix/v2"
|
"github.com/nicklaw5/helix/v2"
|
||||||
|
@ -355,15 +356,18 @@ func (app *application) channelCommandsRoute(w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) statusPageRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (app *application) statusPageRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
commit := common.GetVersion()
|
commit := common.GetCommit()
|
||||||
|
commandsUsed := strconv.Itoa(common.GetCommandsUsed())
|
||||||
started := common.GetUptime().Format("2006-1-2 15:4:5")
|
started := common.GetUptime().Format("2006-1-2 15:4:5")
|
||||||
commitLink := fmt.Sprintf("https://github.com/nouryxd/nourybot/commit/%v", common.GetVersionPure())
|
commitLink := fmt.Sprintf("https://github.com/nouryxd/nourybot/commit/%v", commit)
|
||||||
|
goVersion := common.GetGoVersion()
|
||||||
|
|
||||||
fmt.Print(w, fmt.Sprint(
|
fmt.Fprint(w, fmt.Sprint(
|
||||||
"started: \t"+started+"\n"+
|
"started: \t"+started+"\n"+
|
||||||
"environment: \t"+app.Environment+"\n"+
|
"commands used: \t"+commandsUsed+"\n"+
|
||||||
"commit: \t"+commit+"\n"+
|
"go version: \t"+goVersion+"\n"+
|
||||||
"github: \t"+commitLink,
|
"commit: \t"+commitLink+"\n"+
|
||||||
|
"environment: \t"+app.Environment+"\n",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ import (
|
||||||
func Ping(env string) string {
|
func Ping(env string) string {
|
||||||
botUptime := humanize.Time(common.GetUptime())
|
botUptime := humanize.Time(common.GetUptime())
|
||||||
commandsUsed := common.GetCommandsUsed()
|
commandsUsed := common.GetCommandsUsed()
|
||||||
commit := common.GetVersion()
|
commit := common.GetCommit()
|
||||||
|
goVersion := common.GetGoVersion()
|
||||||
|
|
||||||
return fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v, Running on commit: %v, Env: %v", commandsUsed, botUptime, commit, env)
|
return fmt.Sprintf("Pong! :) Last restart: %v, Commands used: %v, Go version: %v, Commit: %v, Env: %v", botUptime, commandsUsed, goVersion, commit, env)
|
||||||
}
|
}
|
||||||
|
|
38
pkg/common/buildinfo.go
Normal file
38
pkg/common/buildinfo.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import "runtime/debug"
|
||||||
|
|
||||||
|
// GetVersion returns the current git commit hash.
|
||||||
|
func GetGoVersion() string {
|
||||||
|
var version string
|
||||||
|
|
||||||
|
bi, ok := debug.ReadBuildInfo()
|
||||||
|
if ok {
|
||||||
|
version = bi.GoVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersion returns the current git commit hash.
|
||||||
|
func GetCommit() string {
|
||||||
|
var revision string
|
||||||
|
var short string
|
||||||
|
|
||||||
|
bi, ok := debug.ReadBuildInfo()
|
||||||
|
if ok {
|
||||||
|
for _, s := range bi.Settings {
|
||||||
|
switch s.Key {
|
||||||
|
case "vcs.revision":
|
||||||
|
revision = s.Value
|
||||||
|
short = revision[:7]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if revision == "" {
|
||||||
|
return "unavailable"
|
||||||
|
}
|
||||||
|
|
||||||
|
return short
|
||||||
|
}
|
|
@ -1,65 +0,0 @@
|
||||||
// File pretty much completely stolen from a generated
|
|
||||||
// Autostrada project I used a while ago. They don't
|
|
||||||
// require attribution but I still want to give them
|
|
||||||
// credit for their amazing project.
|
|
||||||
// https://autostrada.dev/
|
|
||||||
|
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"runtime/debug"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetVersion returns the current git commit hash.
|
|
||||||
func GetVersion() string {
|
|
||||||
var revision string
|
|
||||||
var short string
|
|
||||||
|
|
||||||
bi, ok := debug.ReadBuildInfo()
|
|
||||||
if ok {
|
|
||||||
for _, s := range bi.Settings {
|
|
||||||
switch s.Key {
|
|
||||||
case "vcs.revision":
|
|
||||||
revision = s.Value
|
|
||||||
short = revision[:7]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if revision == "" {
|
|
||||||
return "unavailable"
|
|
||||||
}
|
|
||||||
|
|
||||||
return short
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVersion returns the current git commit hash.
|
|
||||||
// This function does not add the "-dirty" string at the end of the hash.
|
|
||||||
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 revision
|
|
||||||
}
|
|
||||||
|
|
||||||
return revision
|
|
||||||
}
|
|
Loading…
Reference in a new issue