diff --git a/.gitignore b/.gitignore index 45aa706..942fdf4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,4 @@ NourybotApi NourybotApi.out nourybot-api Nourybot-Web -nourybot-web -nourybot - +nourybot-web \ No newline at end of file diff --git a/cmd/nourybot/main.go b/cmd/nourybot/main.go index fc456df..f50f5e7 100644 --- a/cmd/nourybot/main.go +++ b/cmd/nourybot/main.go @@ -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 { diff --git a/cmd/nourybot/status_page.go b/cmd/nourybot/status_page.go new file mode 100644 index 0000000..17ef848 --- /dev/null +++ b/cmd/nourybot/status_page.go @@ -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)) +}