Added auth

This commit is contained in:
Pijus Kamandulis
2025-07-04 21:05:28 +03:00
parent b3c89a01d0
commit ef247fc843
13 changed files with 297 additions and 80 deletions

View File

@@ -1,7 +1,6 @@
package web
import (
"html/template"
"net/http"
"pool-stats/database"
@@ -9,17 +8,12 @@ import (
)
type IndexPageData struct {
PageDataBase
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)
@@ -30,9 +24,5 @@ func (ws *WebServer) IndexHandler(w http.ResponseWriter, r *http.Request) {
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
}
ws.renderTemplate(w, r, "templates/index.html", &indexData)
}