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
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -23,6 +23,4 @@ NourybotApi
|
||||||
NourybotApi.out
|
NourybotApi.out
|
||||||
nourybot-api
|
nourybot-api
|
||||||
Nourybot-Web
|
Nourybot-Web
|
||||||
nourybot-web
|
nourybot-web
|
||||||
nourybot
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -132,15 +130,6 @@ func main() {
|
||||||
"db.Stats", db.Stats(),
|
"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).
|
// Received a PrivateMessage (normal chat message).
|
||||||
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||||
// sugar.Infow("New Twitch PrivateMessage",
|
// sugar.Infow("New Twitch PrivateMessage",
|
||||||
|
@ -210,7 +199,11 @@ func main() {
|
||||||
|
|
||||||
// Start the timers.
|
// Start the timers.
|
||||||
app.Scheduler.Start()
|
app.Scheduler.Start()
|
||||||
|
|
||||||
|
// Start status page
|
||||||
|
go app.statusPage()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Actually connect to chat.
|
// Actually connect to chat.
|
||||||
err = app.TwitchClient.Connect()
|
err = app.TwitchClient.Connect()
|
||||||
if err != nil {
|
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