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,24 +1,18 @@
package web
import (
"html/template"
"net/http"
"pool-stats/database"
"pool-stats/models"
)
type TopSharesPageData struct {
PageDataBase
Shares []models.ShareLog
}
func (ws *WebServer) TopSharesHandler(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.Must(ws.templates.Clone()).ParseFiles("templates/top_shares.html")
if err != nil {
http.Error(w, "Failed to parse template", 500)
println("Error parsing template:", err.Error())
return
}
topShares := database.ListTopShares(ws.db)
if topShares == nil {
http.Error(w, "Failed to load top shares", 500)
@@ -28,8 +22,6 @@ func (ws *WebServer) TopSharesHandler(w http.ResponseWriter, r *http.Request) {
data := TopSharesPageData{
Shares: topShares,
}
if err := tmpl.ExecuteTemplate(w, "top_shares.html", data); err != nil {
http.Error(w, "Failed to render template", 500)
return
}
ws.renderTemplate(w, r, "templates/top_shares.html", &data)
}