Skip to content

Commit 6a9dbff

Browse files
authored
chore: update echo example (#734)
1 parent 0d80290 commit 6a9dbff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/integration-echo/main.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ func main() {
1515

1616
// This custom Render replaces Echo's echo.Context.Render() with templ's templ.Component.Render().
1717
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
18-
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
19-
ctx.Response().Writer.WriteHeader(statusCode)
20-
return t.Render(ctx.Request().Context(), ctx.Response().Writer)
18+
buf := templ.GetBuffer()
19+
defer templ.ReleaseBuffer(buf)
20+
21+
if err := t.Render(ctx.Request().Context(), buf); err != nil {
22+
return err
23+
}
24+
25+
return ctx.HTML(statusCode, buf.String())
2126
}
2227

2328
func HomeHandler(c echo.Context) error {

0 commit comments

Comments
 (0)