Documentation
¶
Overview ¶
Package chtml provides utilities to render HTML pages and for single-page apps
Index ¶
Constants ¶
This section is empty.
Variables ¶
var URLParams = mux.Vars
URLParams returns the route variables for the current request, if any
var WireModule = wire.NewSet( wire.Struct(new(NewRouterParams), "*"), NewRouter, wire.Struct(new(NewRendererParams), "*"), NewRenderer, NewReaderWriter, )
WireModule can be used as part of google/wire setup for fullstack apps
Functions ¶
This section is empty.
Types ¶
type HTMLDir ¶
HTMLDir is a directory that can be embedded or found on the host system. It should contain sub-directories and files to support the WriteHTML function in ReaderWriter.
type NewRendererParams ¶
NewRendererParams holds the params needed to create Renderer
type NewRouterParams ¶
type NewRouterParams struct {
StaticDir StaticDir
RW *ReaderWriter
}
NewRouterParams holds the params needed to instantiate a new Router
type ReaderWriter ¶
type ReaderWriter struct {
// contains filtered or unexported fields
}
ReaderWriter provides functions to read data from HTTP requests and write response bodies in various formats
func NewReaderWriter ¶
func NewReaderWriter(renderer *Renderer, config cconfig.Config, logger clogger.Logger) *ReaderWriter
NewReaderWriter instantiates a new ReaderWriter with its dependencies
func (*ReaderWriter) WriteHTML ¶
func (rw *ReaderWriter) WriteHTML(w http.ResponseWriter, r *http.Request, p WriteHTMLParams)
WriteHTML writes an HTML response to the provided http.ResponseWriter. Using the given WriteHTMLParams, the HTML is generated with a layout, page, and component templates.
func (*ReaderWriter) WriteHTMLError ¶
func (rw *ReaderWriter) WriteHTMLError(w http.ResponseWriter, r *http.Request, err error)
WriteHTMLError handles the given error. In dev environment, it writes an HTML page with the error. Errors are logged in all environments.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer provides functionality in rendering templatized HTML along with HTML components
func NewRenderer ¶
func NewRenderer(p NewRendererParams) (*Renderer, error)
NewRenderer creates a new Renderer with HTML templates stored in dir and registers the provided HTML components
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router provides routes to serve static assets and the index page for a single-page app
func (*Router) HandleIndexPage ¶
func (ro *Router) HandleIndexPage(w http.ResponseWriter, r *http.Request)
HandleIndexPage renders the index.html page