chi

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

==== File: integrations/chi/chi.go ==== Package chi provides a convenience wrapper for using the templates engine with the go-chi/chi router.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	*templates.Templates
}

Renderer provides a wrapper around templates.Templates for net/http compatible frameworks like chi.

func FromTemplates

func FromTemplates(t *templates.Templates) *Renderer

FromTemplates creates a new Renderer from an existing templates.Templates instance. This is useful if you have already configured a templates.Templates instance.

func NewTemplatesRenderer

func NewTemplatesRenderer(opts ...templates.Option) *Renderer

NewTemplatesRenderer creates a new Renderer with the given options. It is a convenience wrapper around templates.New that returns a chi-compatible renderer.

func (*Renderer) Handler

func (r *Renderer) Handler(templateName string, data interface{}) http.HandlerFunc

Handler returns a http.HandlerFunc that renders the given template with the provided data. This can be used directly as a chi handler. If an error occurs during rendering, it will be logged by the underlying templates.Templates instance.

func (*Renderer) HandlerWithDataFromContext

func (r *Renderer) HandlerWithDataFromContext(templateName string, contextKey interface{}) http.HandlerFunc

HandlerWithDataFromContext returns a http.HandlerFunc that renders the given template, using data from the request context. This can be used directly as a chi handler. The data is retrieved from the request's context using the provided contextKey. If an error occurs, it will be logged by the underlying templates.Templates instance.

func (*Renderer) Render

func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, status int, name string, data interface{}) error

Render executes a template, sets the HTTP status code, and writes the output to the http.ResponseWriter.

Parameters:

  • w: The http.ResponseWriter to write the rendered output to.
  • req: The *http.Request, used to access context for layout selection.
  • status: The HTTP status code to write.
  • name: The template name to render, using the "layout:page" or ":page" syntax.
  • data: The data to pass to the template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL