render

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2018 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	JSONRenderFactory           = iota // JSON Render Factory
	IntendedJSONRenderFactory          // IntendedJSON Render Factory
	PureJSONRenderFactory              // PureJSON Render Factory
	AsciiJSONRenderFactory             // AsciiJSON Render Factory
	JsonpJSONRenderFactory             // JsonpJSON Render Factory
	SecureJSONRenderFactory            // SecureJSON RenderFactory
	XMLRenderFactory                   // XML Render Factory
	StringRenderFactory                // String Render Factory
	RedirectRenderFactory              // Redirect Render Factory
	DataRenderFactory                  // Data Render Factory
	HTMLRenderFactory                  // HTML Render Factory
	HTMLDebugRenderFactory             // HTMLDebug Render Factory
	HTMLProductionRenderFactory        // HTMLProduction Render Factory
	YAMLRenderFactory                  // YAML Render Factory
	MsgPackRenderFactory               // MsgPack Render Factory
	ReaderRenderFactory                // Reader Render Factory
	ProtoBufRenderFactory              // ProtoBuf Render Factory
)

RenderFactory Names

Variables

This section is empty.

Functions

func Register added in v1.4.0

func Register(name int, factory RenderFactory)

Register makes a binding available by the provided name. If Register is called twice with the same name or if binding is nil, it panics.

func WriteContentType added in v1.4.0

func WriteContentType(w http.ResponseWriter, value []string)

func WriteString

func WriteString(w http.ResponseWriter, format string, data []interface{})

WriteString writes data according to its format and write custom ContentType.

Types

type Data

type Data struct {
	ContentType string
	Data        []byte
}

Data contains ContentType and bytes data.

func (Data) Render

func (r Data) Render(w http.ResponseWriter) (err error)

Render (Data) writes data with custom ContentType.

func (Data) WriteContentType added in v1.3.0

func (r Data) WriteContentType(w http.ResponseWriter)

WriteContentType (Data) writes custom ContentType.

type Delims added in v1.3.0

type Delims struct {
	// Left delimiter, defaults to {{.
	Left string
	// Right delimiter, defaults to }}.
	Right string
}

Delims represents a set of Left and Right delimiters for HTML template rendering.

type EmptyRender added in v1.4.0

type EmptyRender struct{}

func (*EmptyRender) Render added in v1.4.0

Render writes data with custom ContentType.

func (*EmptyRender) WriteContentType added in v1.4.0

func (*EmptyRender) WriteContentType(w http.ResponseWriter)

WriteContentType writes custom ContentType.

type EmptyRenderFactory added in v1.4.0

type EmptyRenderFactory struct{}

func (EmptyRenderFactory) Instance added in v1.4.0

func (EmptyRenderFactory) Instance(data interface{}, opts ...interface{}) Render

Instance apply opts to build a new EmptyRender instance

type HTML

type HTML struct {
	Template *template.Template
	Name     string
	Data     interface{}
}

HTML contains template reference and its name with given interface object.

func (HTML) Render

func (r HTML) Render(w http.ResponseWriter) error

Render (HTML) executes template and writes its result with custom ContentType for response.

func (HTML) WriteContentType added in v1.3.0

func (r HTML) WriteContentType(w http.ResponseWriter)

WriteContentType (HTML) writes HTML ContentType.

type HTMLDebug

type HTMLDebug struct {
	Files   []string
	Glob    string
	Delims  Delims
	FuncMap template.FuncMap
}

HTMLDebug contains template delims and pattern and function with file list.

func (HTMLDebug) Instance

func (r HTMLDebug) Instance(name string, data interface{}) Render

Instance (HTMLDebug) returns an HTML instance which it realizes Render interface.

type HTMLProduction

type HTMLProduction struct {
	Template *template.Template
	Delims   Delims
}

HTMLProduction contains template reference and its delims.

func (HTMLProduction) Instance

func (r HTMLProduction) Instance(name string, data interface{}) Render

Instance (HTMLProduction) returns an HTML instance which it realizes Render interface.

type HTMLRender

type HTMLRender interface {
	// Instance returns an HTML instance.
	Instance(string, interface{}) Render
}

HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.

type Reader added in v1.3.0

type Reader struct {
	ContentType   string
	ContentLength int64
	Reader        io.Reader
	Headers       map[string]string
}

Reader contains the IO reader and its length, and custom ContentType and other headers.

func (Reader) Render added in v1.3.0

func (r Reader) Render(w http.ResponseWriter) (err error)

Render (Reader) writes data with custom ContentType and headers.

func (Reader) WriteContentType added in v1.3.0

func (r Reader) WriteContentType(w http.ResponseWriter)

WriteContentType (Reader) writes custom ContentType.

type Redirect

type Redirect struct {
	Code     int
	Request  *http.Request
	Location string
}

Redirect contains the http request reference and redirects status code and location.

func (Redirect) Render

func (r Redirect) Render(w http.ResponseWriter) error

Render (Redirect) redirects the http request to new location and writes redirect response.

func (Redirect) WriteContentType added in v1.3.0

func (r Redirect) WriteContentType(http.ResponseWriter)

WriteContentType (Redirect) don't write any ContentType.

type Render

type Render interface {
	// Render writes data with custom ContentType.
	Render(http.ResponseWriter) error
	// WriteContentType writes custom ContentType.
	WriteContentType(w http.ResponseWriter)
}

Render interface is to be implemented by JSON, XML, HTML, YAML and so on.

type RenderFactory added in v1.4.0

type RenderFactory interface {
	// Instance apply opts to build a new Render instance
	Instance(data interface{}, opts ...interface{}) Render
}

HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.

func Default added in v1.4.0

func Default(name int) RenderFactory

Default returns the appropriate RenderFactory instance based on the render type.

type String

type String struct {
	Format string
	Data   []interface{}
}

String contains the given interface object slice and its format.

func (String) Render

func (r String) Render(w http.ResponseWriter) error

Render (String) writes data with custom ContentType.

func (String) WriteContentType added in v1.3.0

func (r String) WriteContentType(w http.ResponseWriter)

WriteContentType (String) writes Plain ContentType.

Jump to

Keyboard shortcuts

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