This commit is contained in:
2024-09-12 08:57:44 +10:00
commit eb10ca9ca3
35 changed files with 1354 additions and 0 deletions

24
server/handler/handler.go Normal file
View File

@@ -0,0 +1,24 @@
package handler
import (
"context"
"github.com/a-h/templ"
"vctp/db"
"log/slog"
"net/http"
)
// Handler handles requests.
type Handler struct {
Logger *slog.Logger
Database db.Database
}
func (h *Handler) html(ctx context.Context, w http.ResponseWriter, status int, t templ.Component) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(status)
if err := t.Render(ctx, w); err != nil {
h.Logger.Error("Failed to render component", "error", err)
}
}

12
server/handler/home.go Normal file
View File

@@ -0,0 +1,12 @@
package handler
import (
"vctp/components/core"
"vctp/components/home"
"net/http"
)
// Home handles the home page.
func (h *Handler) Home(w http.ResponseWriter, r *http.Request) {
h.html(r.Context(), w, http.StatusOK, core.HTML("Example Site", home.Home()))
}