Documentation ¶
Index ¶
- type Options
- type Render
- func (r *Render) GetHTMLTemplate(filenames ...string) (*htmlTemplate.Template, error)
- func (r *Render) HTML(out io.Writer, data interface{}, entryPoint string, files ...string) error
- func (r *Render) StreamHTML(w http.ResponseWriter, status int, data interface{}, entryPoint string, ...) error
- func (r *Render) StreamText(w http.ResponseWriter, status int, data interface{}, entryPoint string, ...) error
- func (r *Render) Text(out io.Writer, data interface{}, entryPoint string, files ...string) error
- func (r *Render) WriteBinary(w http.ResponseWriter, status int, v []byte)
- func (r *Render) WriteHTML(w http.ResponseWriter, status int, data interface{}, entryPoint string, ...)
- func (r *Render) WriteJSON(w http.ResponseWriter, status int, data interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // A set of functions that are available for templates to call during execution TextFuncs textTemplate.FuncMap HtmlFuncs htmlTemplate.FuncMap // The root directory to load templates from. Directory string // The character set to specify in HTTP responses. Defaults to UTF-8. Encoding string // If DisableCache is true, templates will be reloaded on every call. // By default, caching is enabled, so files are only loaded and parsed the first time. DisableCache bool }
type Render ¶
type Render struct {
// contains filtered or unexported fields
}
Render maintains a template cache and exposes methods for rendering JSON or sets of templates to an HTTP response.
func New ¶
New creates a new instance of Render with the given options, and an empty template cache.
func (*Render) GetHTMLTemplate ¶
func (r *Render) GetHTMLTemplate(filenames ...string) (*htmlTemplate.Template, error)
GetHTMLTemplate returns an HTML template for the given set of filenames by loading it from cache if available, or loading and parsing the files from disk. Returns the template if found or an error if the template couldn't be loaded.
func (*Render) HTML ¶
HTML loads the given set of template files and executes the template named entryPoint against the context data, writing the result to out. Returns error if the template could not be loaded or if executing the template failed.
func (*Render) StreamHTML ¶
func (r *Render) StreamHTML(w http.ResponseWriter, status int, data interface{}, entryPoint string, files ...string) error
StreamHTML calls HTML() on its args and writes the output directly to the response. Does not buffer the executed template before rendering, so it can be used for writing really large responses without consuming memory. If executing the template fails, the status code is not changed; it will remain set to the provided value.
func (*Render) StreamText ¶
func (r *Render) StreamText(w http.ResponseWriter, status int, data interface{}, entryPoint string, files ...string) error
StreamText calls Text() on its args and writes the output directly to the response with a text/plain Content-Type. It calls Text() so that it can accept go text templates rather than simply accepting text. Does not buffer the executed template before rendering, so it can be used for writing really large responses without consuming memory. If executing the template fails, the status code is not changed; it will remain set to the provided value.
func (*Render) Text ¶
Text loads the given set of template files and executes the template named entryPoint against the context data, writing the result to out. Returns error if the template could not be loaded or if executing the template failed.
func (*Render) WriteBinary ¶
func (r *Render) WriteBinary(w http.ResponseWriter, status int, v []byte)
WriteBinary writes raw bytes as binary data to the reponse, with the given status code.
func (*Render) WriteHTML ¶
func (r *Render) WriteHTML(w http.ResponseWriter, status int, data interface{}, entryPoint string, files ...string)
WriteHTML calls HTML() on its args and writes the output to the response with the given status. If the template can't be loaded or executed, the status is set to 500 and error details are written to the response body.