Implement top shares page
This commit is contained in:
@@ -23,6 +23,7 @@ func NewWebServer(db *clover.DB, port int) *WebServer {
|
||||
func (ws *WebServer) Start() error {
|
||||
http.HandleFunc("/", ws.IndexHandler)
|
||||
http.HandleFunc("/shares", ws.SharesHandler)
|
||||
http.HandleFunc("/top-shares", ws.TopSharesHandler)
|
||||
|
||||
address := ":" + fmt.Sprint(ws.port)
|
||||
println("Listening on", address)
|
||||
|
||||
39
web/topSharesHandler.go
Normal file
39
web/topSharesHandler.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"pool-stats/database"
|
||||
"pool-stats/helpers"
|
||||
"pool-stats/models"
|
||||
)
|
||||
|
||||
type TopSharesPageData struct {
|
||||
Shares []models.ShareLog
|
||||
}
|
||||
|
||||
func (ws *WebServer) TopSharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.New("top_shares").Funcs(template.FuncMap{
|
||||
"humanDiff": helpers.HumanDiff,
|
||||
"formatCreateDate": helpers.FormatCreateDate,
|
||||
})
|
||||
tmpl, err := tmpl.ParseFiles("templates/top_shares.html")
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to load template", 500)
|
||||
return
|
||||
}
|
||||
|
||||
topShares := database.ListTopShares(ws.db)
|
||||
if topShares == nil {
|
||||
http.Error(w, "Failed to load top shares", 500)
|
||||
return
|
||||
}
|
||||
|
||||
data := TopSharesPageData{
|
||||
Shares: topShares,
|
||||
}
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
http.Error(w, "Failed to render template", 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user