diff options
Diffstat (limited to 'static.go')
-rw-r--r-- | static.go | 34 |
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) +} |