Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer is responsible for rendering various content and templates like HTML and JSON responses. This implementation caches templates and uses a pool of buffers.
func NewRenderer ¶
New creates a new renderer with the given details.
func (*Renderer) RenderHTML ¶
func (r *Renderer) RenderHTML(w http.ResponseWriter, tmpl string, data any)
RenderHTML calls RenderHTMLStatus with a http.StatusOK (200).
func (*Renderer) RenderHTMLStatus ¶
RenderHTMLStatus renders the given HTML template by name. It attempts to gracefully handle any rendering errors to avoid partial responses sent to the response by writing to a buffer first, then flushing the buffer to the response.
If template rendering fails, a generic 500 page is returned. In dev mode, the error is included on the page. If flushing the buffer to the response fails, an error is logged, but no recovery is attempted.
The buffers are fetched via a sync.Pool to reduce allocations and improve performance.