rest

package
v3.0.0-rc.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentBinary header value for binary data.
	ContentBinary = "application/octet-stream"
	// ContentJSON header value for JSON data.
	ContentJSON = "application/json"
	// ContentJSONP header value for JSONP data.
	ContentJSONP = "application/javascript"
	// ContentLength header constant.
	ContentLength = "Content-Length"
	// ContentText header value for Text data.
	ContentText = "text/plain"
	// ContentType header constant.
	ContentType = "Content-Type"
	// ContentXML header value for XML data.
	ContentXML = "text/xml"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Head
}

Data built-in renderer.

func (Data) Render

func (d Data) Render(ctx *fasthttp.RequestCtx, v interface{}) error

Render a data response.

func (Data) RenderGzip

func (d Data) RenderGzip(ctx *fasthttp.RequestCtx, v interface{}) error

RenderGzip a data response using gzip compression.

type Engine

type Engine interface {
	Render(*fasthttp.RequestCtx, interface{}) error
	//used only if config gzip is enabled
	RenderGzip(*fasthttp.RequestCtx, interface{}) error
}

Engine is the generic interface for all responses.

type Head struct {
	ContentType string
	Status      int
}

Head defines the basic ContentType and Status fields.

func (Head) Write

func (h Head) Write(ctx *fasthttp.RequestCtx)

Write outputs the header content.

type JSON

type JSON struct {
	Head
	Indent        bool
	UnEscapeHTML  bool
	Prefix        []byte
	StreamingJSON bool
}

JSON built-in renderer.

func (JSON) Render

func (j JSON) Render(ctx *fasthttp.RequestCtx, v interface{}) error

Render a JSON response.

func (JSON) RenderGzip

func (j JSON) RenderGzip(ctx *fasthttp.RequestCtx, v interface{}) error

RenderGzip a JSON response using gzip compression.

type JSONP

type JSONP struct {
	Head
	Indent   bool
	Callback string
}

JSONP built-in renderer.

func (JSONP) Render

func (j JSONP) Render(ctx *fasthttp.RequestCtx, v interface{}) error

Render a JSONP response.

func (JSONP) RenderGzip

func (j JSONP) RenderGzip(ctx *fasthttp.RequestCtx, v interface{}) error

RenderGzip a JSONP response using gzip compression.

type Render

type Render struct {
	// Customize Secure with an Options struct.
	Config          config.Rest
	CompiledCharset string
}

Render is a service that provides functions for easily writing JSON, XML, binary data, and HTML templates out to a HTTP Response.

func New

func New(cfg ...config.Rest) *Render

New constructs a new Render instance with the supplied configs.

func (*Render) Data

func (r *Render) Data(ctx *fasthttp.RequestCtx, status int, v []byte) error

Data writes out the raw bytes as binary data.

func (*Render) JSON

func (r *Render) JSON(ctx *fasthttp.RequestCtx, status int, v interface{}) error

JSON marshals the given interface object and writes the JSON response.

func (*Render) JSONP

func (r *Render) JSONP(ctx *fasthttp.RequestCtx, status int, callback string, v interface{}) error

JSONP marshals the given interface object and writes the JSON response.

func (*Render) Markdown

func (r *Render) Markdown(markdownBytes []byte) string

Markdown parses and returns the converted html from a markdown []byte accepts two parameters first is the http status code second is the markdown string

Note that: Works different than the other rest's functions.

func (*Render) Render

func (r *Render) Render(ctx *fasthttp.RequestCtx, e Engine, data interface{}) error

Render is the generic function called by XML, JSON, Data, HTML, and can be called by custom implementations.

func (*Render) Text

func (r *Render) Text(ctx *fasthttp.RequestCtx, status int, v string) error

Text writes out a string as plain text.

func (*Render) XML

func (r *Render) XML(ctx *fasthttp.RequestCtx, status int, v interface{}) error

XML marshals the given interface object and writes the XML response.

type Text

type Text struct {
	Head
}

Text built-in renderer.

func (Text) Render

func (t Text) Render(ctx *fasthttp.RequestCtx, v interface{}) error

Render a text response.

func (Text) RenderGzip

func (t Text) RenderGzip(ctx *fasthttp.RequestCtx, v interface{}) error

RenderGzip a Text response using gzip compression.

type XML

type XML struct {
	Head
	Indent bool
	Prefix []byte
}

XML built-in renderer.

func (XML) Render

func (x XML) Render(ctx *fasthttp.RequestCtx, v interface{}) error

Render an XML response.

func (XML) RenderGzip

func (x XML) RenderGzip(ctx *fasthttp.RequestCtx, v interface{}) error

RenderGzip an XML response using gzip compression.

Jump to

Keyboard shortcuts

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