Release v0.20: регистрация, авторизация, личный кабинет

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-16 17:31:56 +03:00
parent 4ea2b429b3
commit b3e3a06858
23 changed files with 981 additions and 27 deletions
+8 -11
View File
@@ -1,7 +1,6 @@
package handlers
import (
"html/template"
"log"
"net/http"
@@ -10,16 +9,16 @@ import (
)
type HomeHandler struct {
products *repository.ProductRepository
templates *template.Template
products *repository.ProductRepository
pages *Pages
}
func NewHomeHandler(products *repository.ProductRepository, templates *template.Template) *HomeHandler {
return &HomeHandler{products: products, templates: templates}
func NewHomeHandler(products *repository.ProductRepository, pages *Pages) *HomeHandler {
return &HomeHandler{products: products, pages: pages}
}
type homePageData struct {
Title string
Layout
Products []models.Product
Categories []string
TotalItems int
@@ -52,14 +51,12 @@ func (h *HomeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
data := homePageData{
Title: "Главная",
Layout: h.pages.layout(r, "Главная", "home"),
Products: featured,
Categories: categories,
TotalItems: total,
}
data.Success = flashMsg(r, "ok")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.templates.ExecuteTemplate(w, "home.html", data); err != nil {
log.Printf("render home: %v", err)
}
h.pages.render(w, "home.html", data)
}