diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-02-26 19:54:48 +0100 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-18 16:30:36 +0200 |
commit | c8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch) | |
tree | faee639a4c55c5dc3bfc59a5400026822c40221d /tmpl.go | |
download | lens-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.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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) +} |