renderer

package
v0.0.0-...-7d7529a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package renderer documentaton contains the API for this package please follow the link below

Index

Constants

View Source
const (
	// ContentType represents content type
	ContentType string = "Content-Type"
	// ContentJSON represents content type application/json
	ContentJSON string = "application/json"
	// ContentJSONP represents content type application/javascript
	ContentJSONP string = "application/javascript"
	// ContentXML represents content type application/xml
	ContentXML string = "application/xml"
	// ContentYAML represents content type application/x-yaml
	ContentYAML string = "application/x-yaml"
	// ContentHTML represents content type text/html
	ContentHTML string = "text/html"
	// ContentText represents content type text/plain
	ContentText string = "text/plain"
	// ContentBinary represents content type application/octet-stream
	ContentBinary string = "application/octet-stream"

	// ContentDisposition describes contentDisposition
	ContentDisposition string = "Content-Disposition"
)

Variables

This section is empty.

Functions

func AddTokenCSRF

func AddTokenCSRF(w http.ResponseWriter, r *http.Request, inf interface{}) interface{}

Types

type BayurDT

type BayurDT struct {
	CsrfToken string `json:"csrf_token"`
}

type BayurData

type BayurData struct {
	CsrfToken  string `json:"csrf_token"`
	AppVersion int    `json:"app_version"`
}

type Options

type Options struct {
	// Charset represents the Response charset; default: utf-8
	Charset string
	// ContentJSON represents the Content-Type for JSON
	ContentJSON string
	// ContentJSONP represents the Content-Type for JSONP
	ContentJSONP string
	// ContentXML represents the Content-Type for XML
	ContentXML string
	// ContentYAML represents the Content-Type for YAML
	ContentYAML string
	// ContentHTML represents the Content-Type for HTML
	ContentHTML string
	// ContentText represents the Content-Type for Text
	ContentText string
	// ContentBinary represents the Content-Type for octet-stream
	ContentBinary string

	// UnEscapeHTML set UnEscapeHTML for JSON; default false
	UnEscapeHTML bool
	// DisableCharset set DisableCharset in Response Content-Type
	DisableCharset bool
	// Debug set the debug mode. if debug is true then every time "VIEW" call parse the templates
	Debug bool
	// JSONIndent set JSON Indent in response; default false
	JSONIndent bool
	// XMLIndent set XML Indent in response; default false
	XMLIndent bool

	// JSONPrefix set Prefix in JSON response
	JSONPrefix string
	// XMLPrefix set Prefix in XML response
	XMLPrefix string

	// TemplateDir set the Template directory
	TemplateDir string
	// TemplateExtension set the Template extension
	TemplateExtension string
	// LeftDelim set template left delimiter default is {{
	LeftDelim string
	// RightDelim set template right delimiter default is }}
	RightDelim string
	// LayoutExtension set the Layout extension
	LayoutExtension string
	// FuncMap contain function map for template
	FuncMap []template.FuncMap
	// ParseGlobPattern contain parse glob pattern
	ParseGlobPattern string
}

Options describes an option type

type Render

type Render struct {
	// contains filtered or unexported fields
}

Render describes a renderer type

func New

func New(opts ...Options) *Render

New return a new instance of a pointer to Render

func (*Render) Binary

func (r *Render) Binary(w http.ResponseWriter, status int, reader io.Reader, filename string, inline bool) error

Binary serve file as application/octet-stream response; you may add ContentDisposition by your own.

func (*Render) Charset

func (r *Render) Charset(c string) *Render

Charset change the Charset for response on the fly

func (*Render) Delims

func (r *Render) Delims(left, right string) *Render

Delims set template delimiter on the fly

func (*Render) DisableCharset

func (r *Render) DisableCharset(b bool) *Render

DisableCharset change the DisableCharset for JSON on the fly

func (*Render) EscapeHTML

func (r *Render) EscapeHTML(b bool) *Render

EscapeHTML change the EscapeHTML for JSON on the fly

func (*Render) File

func (r *Render) File(w http.ResponseWriter, status int, reader io.Reader, filename string, inline bool) error

File serve file as response from io.Reader

func (*Render) FileDownload

func (r *Render) FileDownload(w http.ResponseWriter, status int, fpath, name string) error

FileDownload serve file as response with content-disposition value attachment

func (*Render) FileView

func (r *Render) FileView(w http.ResponseWriter, status int, fpath, name string) error

FileView serve file as response with content-disposition value inline

func (*Render) FuncMap

func (r *Render) FuncMap(fmap template.FuncMap) *Render

FuncMap set template FuncMap on the fly

func (*Render) HTML

func (r *Render) HTML(w http.ResponseWriter, status int, name string, v interface{}) error

HTML render html from template.Glob patterns and execute template by name. See README.md for detail example.

func (*Render) HTMLString

func (r *Render) HTMLString(w http.ResponseWriter, status int, html string) error

HTMLString render string as html. Note: You must provide trusted html when using this method

func (*Render) JSON

func (r *Render) JSON(w http.ResponseWriter, status int, v interface{}) error

JSON serve data as JSON as response

func (*Render) JSONIndent

func (r *Render) JSONIndent(b bool) *Render

JSONIndent change the JSONIndent for JSON on the fly

func (*Render) JSONP

func (r *Render) JSONP(w http.ResponseWriter, status int, callback string, v interface{}) error

JSONP serve data as JSONP response

func (*Render) NoContent

func (r *Render) NoContent(w http.ResponseWriter) error

NoContent serve success but no content response

func (*Render) Render

func (r *Render) Render(w http.ResponseWriter, status int, v interface{}) error

Render serve raw response where you have to build the headers, body

func (*Render) String

func (r *Render) String(w http.ResponseWriter, status int, v interface{}) error

String serve string content as text/plain response

func (*Render) Template

func (r *Render) Template(w http.ResponseWriter, rq *http.Request, status int, tpls []string, v interface{}) error

Template build html from template and serve html content as response. See README.md for detail example.

func (*Render) View

func (r *Render) View(w http.ResponseWriter, status int, name string, v interface{}) error

View build html from template directory and serve html content as response. See README.md for detail example.

func (*Render) XML

func (r *Render) XML(w http.ResponseWriter, status int, v interface{}) error

XML serve data as XML response

func (*Render) XMLIndent

func (r *Render) XMLIndent(b bool) *Render

XMLIndent change the XMLIndent for XML on the fly

func (*Render) YAML

func (r *Render) YAML(w http.ResponseWriter, status int, v interface{}) error

YAML serve data as YAML response

Jump to

Keyboard shortcuts

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