chtml

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package chtml provides utilities to render HTML pages and for single-page apps

Index

Constants

This section is empty.

Variables

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

func LoadConfig added in v0.2.0

func LoadConfig(appConfig cconfig.Loader) (Config, error)

LoadConfig loads Config from app config

type HTMLDir

type HTMLDir fs.FS

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 NewRouter

func NewRouter(p NewRouterParams) *Router

NewRouter instantiates a new Router

func (*Router) HandleIndexPage

func (ro *Router) HandleIndexPage(w http.ResponseWriter, r *http.Request)

HandleIndexPage renders the index.html page

func (*Router) Routes

func (ro *Router) Routes() []chttp.Route

Routes defines the HTTP routes for this router

type StaticDir

type StaticDir fs.FS

StaticDir represents a directory that holds static resources (JS, CSS, images, etc.)

type WriteHTMLParams

type WriteHTMLParams struct {
	StatusCode     int
	Error          error
	Data           interface{}
	PageTemplate   string
	LayoutTemplate string
}

WriteHTMLParams holds the params for the WriteHTML function in ReaderWriter

Directories

Path Synopsis
Package chtmltest provides utilities to test the chtml package
Package chtmltest provides utilities to test the chtml package

Jump to

Keyboard shortcuts

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