feat: templates prototype
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"forge.capytal.company/capytalcode/project-comicverse/templates"
|
||||
"forge.capytal.company/loreddev/x/smalltrip"
|
||||
"forge.capytal.company/loreddev/x/smalltrip/exceptions"
|
||||
"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.Middleware())
|
||||
|
||||
r.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
|
||||
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
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) {
|
||||
exceptions.InternalServerError(errors.New("TEST ERROR"),
|
||||
@@ -39,3 +43,6 @@ func New(assertions tinyssert.Assertions, log *slog.Logger, dev bool) http.Handl
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
18
templates/templates.go
Normal file
18
templates/templates.go
Normal 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
12
templates/test/test.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello, world 2</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user