Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 8 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetJSONMarshal

func ResetJSONMarshal(fn JSONMarshaler)

func ResetStdJSONMarshal

func ResetStdJSONMarshal()

Types

type Data

type Data struct {
	ContentType string
	Data        []byte
}

Data contains ContentType and bytes data.

func (Data) Render

func (r Data) Render(resp *protocol.Response) (err error)

Render (Data) writes data with custom ContentType.

func (Data) WriteContentType

func (r Data) WriteContentType(resp *protocol.Response)

WriteContentType (Data) writes custom ContentType.

type Delims

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 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(resp *protocol.Response) error

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

func (HTML) WriteContentType

func (r HTML) WriteContentType(resp *protocol.Response)

WriteContentType (HTML) writes HTML ContentType.

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 JSONMarshaler

type JSONMarshaler func(v interface{}) ([]byte, error)

customize json.Marshal as you like

type JSONRender

type JSONRender struct {
	Data interface{}
}

JSON contains the given interface object.

func (JSONRender) Render

func (r JSONRender) Render(resp *protocol.Response) error

Render (JSON) writes data with custom ContentType.

func (JSONRender) WriteContentType

func (r JSONRender) WriteContentType(resp *protocol.Response)

WriteContentType (JSON) writes JSON ContentType.

type ProtoBuf

type ProtoBuf struct {
	Data interface{}
}

ProtoBuf contains the given interface object.

func (ProtoBuf) Render

func (r ProtoBuf) Render(resp *protocol.Response) error

Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.

func (ProtoBuf) WriteContentType

func (r ProtoBuf) WriteContentType(resp *protocol.Response)

WriteContentType (ProtoBuf) writes ProtoBuf ContentType.

type PureJSON

type PureJSON struct {
	Data interface{}
}

PureJSON contains the given interface object.

func (PureJSON) Render

func (r PureJSON) Render(resp *protocol.Response) (err error)

Render (JSON) writes data with custom ContentType.

func (PureJSON) WriteContentType

func (r PureJSON) WriteContentType(resp *protocol.Response)

WriteContentType (JSON) writes JSON ContentType.

type Render

type Render interface {
	// Render writes data with custom ContentType.
	// Do not panic inside, RequestContext will handle it.
	Render(resp *protocol.Response) error
	// WriteContentType writes custom ContentType.
	WriteContentType(resp *protocol.Response)
}

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

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(resp *protocol.Response) error

Render (String) writes data with custom ContentType.

func (String) WriteContentType

func (r String) WriteContentType(resp *protocol.Response)

WriteContentType (String) writes Plain ContentType.

type XML

type XML struct {
	Data interface{}
}

XML contains the given interface object.

func (XML) Render

func (r XML) Render(resp *protocol.Response) error

Render (XML) encodes the given interface object and writes data with custom ContentType.

func (XML) WriteContentType

func (r XML) WriteContentType(w *protocol.Response)

WriteContentType (XML) writes XML ContentType for response.

Jump to

Keyboard shortcuts

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