This commit is contained in:
2026-05-12 01:13:01 +02:00
commit bf304e17c9
46 changed files with 4358 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
package render
import (
"net/http"
"prestaproxy/internal/assets"
"prestaproxy/internal/viewmodel"
"prestaproxy/templates"
)
type Engine struct {
assets assets.Manifest
}
func New(manifest assets.Manifest) *Engine {
return &Engine{assets: manifest}
}
func (e *Engine) Product(w http.ResponseWriter, r *http.Request, data viewmodel.ProductPageData) error {
startHTMLStream(w)
component := templates.ProductPage(data, e.assets.CSSPath("app.css"), e.assets.JSPath("app.js"))
return component.Render(r.Context(), w)
}
func (e *Engine) Category(w http.ResponseWriter, r *http.Request, data viewmodel.CategoryPageData) error {
startHTMLStream(w)
component := templates.CategoryPage(data, e.assets.CSSPath("app.css"), e.assets.JSPath("app.js"))
return component.Render(r.Context(), w)
}
func startHTMLStream(w http.ResponseWriter) {
if w == nil {
return
}
headers := w.Header()
if headers.Get("Content-Type") == "" {
headers.Set("Content-Type", "text/html; charset=utf-8")
}
w.WriteHeader(http.StatusOK)
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
}