aboutsummaryrefslogtreecommitdiff
path: root/tmpl.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-02-26 19:54:48 +0100
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-18 16:30:36 +0200
commitc8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch)
treefaee639a4c55c5dc3bfc59a5400026822c40221d /tmpl.go
downloadlens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.gz
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.bz2
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.zip
feat: Inicial commit
It contains rough template for the server and runners. It contains rough template for the server and runners.
Diffstat (limited to 'tmpl.go')
-rw-r--r--tmpl.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/tmpl.go b/tmpl.go
new file mode 100644
index 0000000..b11f962
--- /dev/null
+++ b/tmpl.go
@@ -0,0 +1,29 @@
+package img
+
+import (
+ "embed"
+ "fmt"
+ "html/template"
+ "io"
+)
+
+//go:embed templates/*.html
+var TemplateFS embed.FS
+
+var Template *template.Template
+
+type HTMLView[T any] struct {
+ Title string
+ Username string
+ Data T
+}
+
+func Render[T any](w io.Writer, page string, view *HTMLView[T]) error {
+ pageFile := fmt.Sprintf("templates/%s", page)
+ tmpl, err := template.New("").ParseFS(TemplateFS, "templates/layout.html", pageFile)
+ if err != nil {
+ return err
+ }
+
+ return tmpl.ExecuteTemplate(w, page, view)
+}