Event replay and cleanup
This commit is contained in:
parent
2560410820
commit
97bf66c191
8 changed files with 447 additions and 39 deletions
35
internal/web/web.go
Normal file
35
internal/web/web.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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())
|
||||
|
||||
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>")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue