Refactor pool-stats into modular code structure
This commit is contained in:
20
web/handlers.go
Normal file
20
web/handlers.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"pool-stats/database"
|
||||
"pool-stats/stats"
|
||||
)
|
||||
|
||||
func (h database.Handlers) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
shareStats, err := stats.GetStats(h.DB)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to load stats", 500)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.ParseFiles("templates/index.html"))
|
||||
tmpl.Execute(w, shareStats)
|
||||
}
|
||||
Reference in New Issue
Block a user