templates/example_test.go

30 lines
604 B
Go
Raw Normal View History

2025-01-12 10:47:45 +00:00
package templates_test
import (
"embed"
"fmt"
"io"
"net/http"
"net/http/httptest"
"git.bivouac.wiki/use/templates"
)
//go:embed example_templates
var tpfs embed.FS
func ExampleTemplates() {
a := templates.NewTemplates(tpfs, "example_templates", "base.html", "nav.html")
v := struct{}{}
r := httptest.NewRequest(http.MethodGet, "home.html", nil)
w := httptest.NewRecorder()
a.TemplateEnd("home.html", w, r, v)
res := w.Result()
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
fmt.Errorf("expected error to be nil got %v", err)
}
fmt.Println(string(data))
}