ActionResult

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteMsgPack

func WriteMsgPack(w http.ResponseWriter, obj interface{}) error

Types

type AsciiJson

type AsciiJson struct {
	Data interface{}
}

AsciiJSON contains the given interface object.

func (AsciiJson) Render

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

使用Ascii JSON 生成仅有 ASCII字符的JSON,非ASCII字符将会被转义 ActionResult (AsciiJSON) marshals the given interface object and writes it with custom ContentType.

func (AsciiJson) WriteContentType

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

type Data

type Data struct {
	ContentType string
	Data        []byte
}

Data contains ContentType and bytes data.

func FormFile

func FormFile(filename string) (Data, error)

func FormFileStream

func FormFileStream(data []byte) Data

func (Data) Render

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

func (Data) WriteContentType

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

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(w http.ResponseWriter) error

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

func (HTML) WriteContentType

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{}) IActionResult

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{}) IActionResult

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

type HTMLRender

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

HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.

type IActionResult

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

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

type IndentedJson

type IndentedJson struct {
	Data interface{}
}

func (IndentedJson) Render

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

ActionResult (IndentedJSON) marshals the given interface object and writes it with custom ContentType.

func (IndentedJson) WriteContentType

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

type Json

type Json struct {
	Data interface{}
}

func (Json) Render

func (d Json) Render(w http.ResponseWriter) (err error)

ActionResult (JSON) writes data with custom ContentType.

func (Json) WriteContentType

func (d Json) WriteContentType(w http.ResponseWriter)

type Jsonp

type Jsonp struct {
	Callback string
	Data     interface{}
}

func (Jsonp) Render

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

callback(json) ActionResult (Jsonp JSON) marshals the given interface object and writes it and its callback with custom ContentType.

func (Jsonp) WriteContentType

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

type MsgPack

type MsgPack struct {
	Data interface{}
}

func (MsgPack) Render

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

func (MsgPack) WriteContentType

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

type ProtoBuf

type ProtoBuf struct {
	Data interface{}
}

func (ProtoBuf) Render

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

func (ProtoBuf) WriteContentType

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

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(w http.ResponseWriter) error

原始字符串,不通过Html编码 ActionResult (PureJSON) writes custom ContentType and encodes the given interface object.

func (PureJson) WriteContentType

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

WriteContentType (PureJSON) writes custom ContentType.

type Redirect

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

func (Redirect) Render

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

func (Redirect) WriteContentType

func (r Redirect) WriteContentType(http.ResponseWriter)

type SecureJson

type SecureJson struct {
	Prefix string
	Data   interface{}
}

func (SecureJson) Render

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

SecureJSON 用来防止json劫持。 如果给定的结构体是数值型,默认预置“while(1)” 到response body ActionResult (SecureJSON) marshals the given interface object and writes it with custom ContentType.

func (SecureJson) WriteContentType

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

type Text

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

func (Text) Render

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

func (Text) WriteContentType

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

type XML

type XML struct {
	Data interface{}
}

func (XML) Render

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

func (XML) WriteContentType

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

type YAML

type YAML struct {
	Data interface{}
}

func (YAML) Render

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

func (YAML) WriteContentType

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

Jump to

Keyboard shortcuts

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