2025-01-08 00:47:49 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"gitlab.com/whom/bingobot/internal/activity"
|
|
|
|
|
"gitlab.com/whom/bingobot/internal/config"
|
|
|
|
|
"gitlab.com/whom/bingobot/internal/logging"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Start() error {
|
|
|
|
|
frag := config.Get().LocalWebEndpointListen
|
|
|
|
|
http.HandleFunc("/", HandleHttpRequest)
|
|
|
|
|
go logging.Error(http.ListenAndServe(frag, nil).Error())
|
|
|
|
|
|
2025-01-13 15:45:07 -08:00
|
|
|
logging.Debug("Web handlers started")
|
2025-01-08 00:47:49 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func HandleHttpRequest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
fmt.Fprintf(w, "<html>")
|
|
|
|
|
fmt.Fprintf(w, "<h1> User Activity Metrics </h1>")
|
|
|
|
|
fmt.Fprintf(w, "<p> number of the last %d days a user has been active </p>",
|
|
|
|
|
config.Get().UserEventLifespanDays)
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "<table>")
|
|
|
|
|
fmt.Fprintf(w, "<tr><th>User</th><th>Days</th></tr>")
|
|
|
|
|
for k, v := range activity.GetActivitySnapshot() {
|
|
|
|
|
fmt.Fprintf(w, "<tr><td>%s</td><td>%d</td></tr>",
|
|
|
|
|
k, len(v))
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(w, "</table>")
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "</html>")
|
|
|
|
|
}
|