aboutsummaryrefslogtreecommitdiff
path: root/static.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-25 16:03:36 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-25 16:12:05 +0200
commitd6cf67b3d7747b6274d92e394d75d348060fa5f5 (patch)
tree8c48f947e7ab732a38b15eab6a898cb14caa1669 /static.go
parent57b41ad766b3c4505672c12f058f10c7a132dd5b (diff)
downloadlens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.tar.gz
lens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.tar.bz2
lens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.zip
feat: Add static file to output bin
Now the final binary has a standalone web server including necessary static file.
Diffstat (limited to 'static.go')
-rw-r--r--static.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/static.go b/static.go
new file mode 100644
index 0000000..1c6a086
--- /dev/null
+++ b/static.go
@@ -0,0 +1,34 @@
+package img
+
+import (
+ "embed"
+ "fmt"
+ "html/template"
+ "io"
+)
+
+var (
+ //go:embed templates/*.html
+ TemplateFS embed.FS
+
+ //go:embed static/*
+ StaticFS embed.FS
+
+ 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)
+}