mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
30 lines
653 B
Go
30 lines
653 B
Go
package view
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/onsonr/sonr/pkg/nebula/routes"
|
|
)
|
|
|
|
// render renders a templ.Component
|
|
func Render(r routes.Route) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
// Create a buffer to store the rendered HTML
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
// Render the component to the buffer
|
|
err := r.Component(c).Render(c.Request().Context(), buf)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set the content type
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
|
|
|
// Write the buffered content to the response
|
|
_, err = c.Response().Write(buf.Bytes())
|
|
return err
|
|
}
|
|
}
|