mirror of
https://github.com/cf-sonr/motr.git
synced 2026-01-12 02:59:13 +00:00
* feat: enhance modularity by relocating core packages * refactor: move chart components to dashboard package * refactor: restructure database access layer * refactor: rename credential descriptor to credentials for clarity * feat: enhance development environment configuration for database interactions * feat: integrate go-task for database migrations * feat: introduce middleware for market data and WebAuthn
36 lines
773 B
Go
36 lines
773 B
Go
package render
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/a-h/templ"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type (
|
|
EchoView func(c echo.Context) error
|
|
EchoViewFunc func(c echo.Context, b templ.Component) error
|
|
EchoPartialView func(c echo.Context) templ.Component
|
|
)
|
|
|
|
func View(c echo.Context, cmp templ.Component) error {
|
|
// Create a buffer to store the rendered HTML
|
|
buf := &bytes.Buffer{}
|
|
// Render the component to the buffer
|
|
err := cmp.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())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.Response().WriteHeader(200)
|
|
return nil
|
|
}
|