Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Data
- type Engine
- type Head
- type JSON
- type JSONP
- type Render
- func (r *Render) Data(ctx *fasthttp.RequestCtx, status int, v []byte) error
- func (r *Render) JSON(ctx *fasthttp.RequestCtx, status int, v interface{}) error
- func (r *Render) JSONP(ctx *fasthttp.RequestCtx, status int, callback string, v interface{}) error
- func (r *Render) Markdown(markdownBytes []byte) string
- func (r *Render) Render(ctx *fasthttp.RequestCtx, e Engine, data interface{}) error
- func (r *Render) Text(ctx *fasthttp.RequestCtx, status int, v string) error
- func (r *Render) XML(ctx *fasthttp.RequestCtx, status int, v interface{}) error
- type Text
- type XML
Constants ¶
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 ¶
var (
// DefaultCharset character encoding for rest rendering
DefaultCharset = "UTF-8"
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Appends the given character set to the Content-Type header. Default is "UTF-8".
Charset string
// Gzip enable it if you want to render with gzip compression. Default is false
Gzip bool
// Outputs human readable JSON.
IndentJSON bool
// Outputs human readable XML. Default is false.
IndentXML bool
// Prefixes the JSON output with the given bytes. Default is false.
PrefixJSON []byte
// Prefixes the XML output with the given bytes.
PrefixXML []byte
// Unescape HTML characters "&<>" to their original values. Default is false.
UnEscapeHTML bool
// Streams JSON responses instead of marshalling prior to sending. Default is false.
StreamingJSON bool
// Disables automatic rendering of http.StatusInternalServerError when an error occurs. Default is false.
DisableHTTPErrorRendering bool
// MarkdownSanitize sanitizes the markdown. Default is false.
MarkdownSanitize bool
}
Config is a struct for specifying configuration options for the rest.Render object.
func (Config) MergeSingle ¶
MergeSingle merges the default with the given config and returns the result
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 JSON ¶
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 ¶
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
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 (*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) Markdown ¶
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.
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 ¶
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.