mirror of
https://github.com/rjNemo/payit
synced 2026-06-06 02:16:40 +00:00
Introduced LoggerMiddleware for HTTP request logging. Refactored handler methods to return http.HandlerFunc for improved composability. Updated route registration and tests to use new handler signatures.
32 lines
829 B
Go
32 lines
829 B
Go
package web
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type checkoutPageData struct {
|
|
ProductName string
|
|
ProductDescription string
|
|
PriceDisplay string
|
|
Currency string
|
|
}
|
|
|
|
func (h *Handler) renderCheckoutPage() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
price := float64(h.cfg.Product.PriceCents) / 100
|
|
data := checkoutPageData{
|
|
ProductName: h.cfg.Product.Name,
|
|
ProductDescription: h.cfg.Product.Description,
|
|
PriceDisplay: fmt.Sprintf("$%.2f", price),
|
|
Currency: strings.ToUpper(h.cfg.Product.Currency),
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
if err := h.page.ExecuteTemplate(w, "index.html", data); err != nil {
|
|
http.Error(w, "failed to render page", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|
|
}
|