mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add more information to status page
This commit is contained in:
parent
9747dbc50b
commit
4592b3b52f
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -24,5 +24,3 @@ NourybotApi.out
|
|||
nourybot-api
|
||||
Nourybot-Web
|
||||
nourybot-web
|
||||
nourybot
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
22
cmd/nourybot/status_page.go
Normal file
22
cmd/nourybot/status_page.go
Normal 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))
|
||||
}
|
Loading…
Reference in a new issue