42 lines
899 B
Go
42 lines
899 B
Go
package web
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
|
|
"pool-stats/database"
|
|
"pool-stats/helpers"
|
|
"pool-stats/models"
|
|
)
|
|
|
|
type IndexPageData struct {
|
|
Stats []models.TimeWindowHighShare
|
|
}
|
|
|
|
func (ws *WebServer) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|
tmpl := template.New("index").Funcs(template.FuncMap{
|
|
"humanDiff": helpers.HumanDiff,
|
|
"formatCreateDate": helpers.FormatCreateDate,
|
|
})
|
|
tmpl, err := tmpl.ParseFiles("templates/index.html")
|
|
if err != nil {
|
|
http.Error(w, "Failed to load template", 500)
|
|
return
|
|
}
|
|
|
|
tws := database.GetTimeWindowHighShares(ws.db)
|
|
if tws == nil {
|
|
http.Error(w, "Failed to load time window high shares", 500)
|
|
return
|
|
}
|
|
|
|
indexData := IndexPageData{
|
|
Stats: tws,
|
|
}
|
|
if err := tmpl.Execute(w, indexData); err != nil {
|
|
http.Error(w, "Failed to render template", 500)
|
|
println("Error rendering template:", err.Error())
|
|
return
|
|
}
|
|
}
|