add more information to status page

This commit is contained in:
lyx0 2023-12-10 20:13:06 +01:00
parent 9747dbc50b
commit 4592b3b52f
3 changed files with 27 additions and 14 deletions

2
.gitignore vendored
View file

@ -24,5 +24,3 @@ NourybotApi.out
nourybot-api
Nourybot-Web
nourybot-web
nourybot

View file

@ -4,8 +4,6 @@ import (
"context"
"database/sql"
"fmt"
"io"
"net/http"
"os"
"time"
@ -132,15 +130,6 @@ func main() {
"db.Stats", db.Stats(),
)
go func() {
statusHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "up")
}
http.HandleFunc("/status", statusHandler)
sugar.Fatal(http.ListenAndServe(":8080", nil))
}()
// Received a PrivateMessage (normal chat message).
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
// sugar.Infow("New Twitch PrivateMessage",
@ -210,7 +199,11 @@ func main() {
// Start the timers.
app.Scheduler.Start()
// Start status page
go app.statusPage()
})
// Actually connect to chat.
err = app.TwitchClient.Connect()
if err != nil {

View file

@ -0,0 +1,22 @@
package main
import (
"fmt"
"io"
"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())
statusHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, fmt.Sprintf("up\n\nlast restart:\t %v\nenv: %v\tcommit: \t%v", botUptime, app.Environment, commit))
}
http.HandleFunc("/status", statusHandler)
app.Log.Fatal(http.ListenAndServe(":8080", nil))
}