initial
This commit is contained in:
24
server/handler/handler.go
Normal file
24
server/handler/handler.go
Normal 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
12
server/handler/home.go
Normal 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()))
|
||||
}
|
Reference in New Issue
Block a user