Documentation ¶
Overview ¶
Package chtml provides utilities to render HTML pages and for single-page apps
Index ¶
Constants ¶
This section is empty.
Variables ¶
var WireModule = wire.NewSet( LoadConfig, 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 Config ¶ added in v0.2.0
type Config struct { DevMode bool `toml:"dev_mode"` EnableSinglePageRouting bool `toml:"enable_single_page_routing"` }
Config holds params to configure chtml
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 ¶
type NewRendererParams struct { HTMLDir HTMLDir StaticDir StaticDir Config Config Logger clogger.Logger }
NewRendererParams holds the params needed to create Renderer
type NewRouterParams ¶
type NewRouterParams struct { StaticDir StaticDir RW *ReaderWriter Config Config }
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 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 render_error is configured to true, it writes an HTML page with the error. Errors are always logged.
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