This commit is contained in:
anthdm
2024-04-24 19:52:05 +02:00
commit af9c83cbd0
31 changed files with 1515 additions and 0 deletions

10
handlers/auth.go Normal file
View File

@@ -0,0 +1,10 @@
package handlers
import (
"gothstarter/views/auth"
"net/http"
)
func HandleLoginIndex(w http.ResponseWriter, r *http.Request) error {
return Render(w, r, auth.Login())
}

10
handlers/home.go Normal file
View File

@@ -0,0 +1,10 @@
package handlers
import (
"gothstarter/views/home"
"net/http"
)
func HandleHome(w http.ResponseWriter, r *http.Request) error {
return Render(w, r, home.Index())
}

22
handlers/shared.go Normal file
View File

@@ -0,0 +1,22 @@
package handlers
import (
"log/slog"
"net/http"
"github.com/a-h/templ"
)
type HTTPHandler func(w http.ResponseWriter, r *http.Request) error
func Make(h HTTPHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := h(w, r); err != nil {
slog.Error("HTTP handler error", "err", err, "path", r.URL.Path)
}
}
}
func Render(w http.ResponseWriter, r *http.Request, c templ.Component) error {
return c.Render(r.Context(), w)
}