feat: templates prototype

This commit is contained in:
Guz
2025-03-05 13:45:19 -03:00
parent 7b6796e2c1
commit f13dc0fe0f
4 changed files with 40 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"log/slog" "log/slog"
"net/http" "net/http"
"forge.capytal.company/capytalcode/project-comicverse/templates"
"forge.capytal.company/loreddev/x/smalltrip" "forge.capytal.company/loreddev/x/smalltrip"
"forge.capytal.company/loreddev/x/smalltrip/exceptions" "forge.capytal.company/loreddev/x/smalltrip/exceptions"
"forge.capytal.company/loreddev/x/smalltrip/middleware" "forge.capytal.company/loreddev/x/smalltrip/middleware"
@@ -24,9 +25,12 @@ func New(assertions tinyssert.Assertions, log *slog.Logger, dev bool) http.Handl
r.Use(exceptions.PanicMiddleware()) r.Use(exceptions.PanicMiddleware())
r.Use(exceptions.Middleware()) r.Use(exceptions.Middleware())
r.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("Hello world")) err := templates.Templates().ExecuteTemplate(w, "test.html", nil)
if err != nil {
exceptions.InternalServerError(err).ServeHTTP(w, r)
}
}) })
r.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
exceptions.InternalServerError(errors.New("TEST ERROR"), exceptions.InternalServerError(errors.New("TEST ERROR"),
@@ -39,3 +43,6 @@ func New(assertions tinyssert.Assertions, log *slog.Logger, dev bool) http.Handl
return r return r
} }
func dashboard(w http.ResponseWriter, r *http.Request) {
}

View File

@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html> <html>
<head> <head>

18
templates/templates.go Normal file
View File

@@ -0,0 +1,18 @@
package templates
import (
"embed"
"html/template"
)
//go:embed *.html test/*.html
var embedded embed.FS
var temps = template.Must(template.ParseFS(embedded,
"*.html",
"test/*.html",
))
func Templates() *template.Template {
return temps
}

12
templates/test/test.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Hello, world 2</h1>
</body>
</html>