39 lines
834 B
Go
39 lines
834 B
Go
package web
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
|
|
"pool-stats/database"
|
|
"pool-stats/models"
|
|
)
|
|
|
|
type IndexPageData struct {
|
|
Stats []models.TimeWindowHighShare
|
|
}
|
|
|
|
func (ws *WebServer) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|
tmpl, err := template.Must(ws.templates.Clone()).ParseFiles("templates/index.html")
|
|
if err != nil {
|
|
http.Error(w, "Failed to parse template", 500)
|
|
println("Error parsing template:", err.Error())
|
|
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.ExecuteTemplate(w, "index.html", indexData); err != nil {
|
|
http.Error(w, "Failed to render template", 500)
|
|
println("Error rendering template:", err.Error())
|
|
return
|
|
}
|
|
}
|