move template in bin

This commit is contained in:
Adrian Zürcher
2025-08-05 17:17:02 +02:00
parent 0e8864d4da
commit dd5ebb60fd
3 changed files with 62 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package handlers
import (
"embed"
"encoding/json"
"html/template"
"net/http"
@@ -8,16 +9,18 @@ import (
)
type HTopHandler struct {
Table *models.HtopTable
Table *models.HtopTable
templates *embed.FS
}
func NewHTopHandler() (*HTopHandler, error) {
func NewHTopHandler(templates *embed.FS) (*HTopHandler, error) {
table, err := models.NewTable()
if err != nil {
return nil, err
}
return &HTopHandler{
Table: table,
Table: table,
templates: templates,
}, nil
}
@@ -38,14 +41,18 @@ func (h *HTopHandler) UpdateHTop(w http.ResponseWriter, r *http.Request) {
// Detect HTMX request via the HX-Request header
if r.Header.Get("HX-Request") == "true" {
tmpl := template.Must(
template.New("table.html").Funcs(funcMap).ParseFiles("templates/htop/table.html"),
template.New("table.html").Funcs(funcMap).ParseFS(
h.templates,
"templates/htop/table.html",
),
)
tmpl.Execute(w, h.Table)
return
}
tmpl := template.Must(
template.New("htop.html").Funcs(funcMap).ParseFiles(
template.New("htop.html").Funcs(funcMap).ParseFS(
h.templates,
"templates/htop/htop.html",
"templates/htop/table.html",
),