render

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 5 Imported by: 1

README

render this is gin render package, but with option tags

GoDoc Go.Dev reference Build Status codecov Action Status Go Report Card Licence Tag

Build with jsoniter

render uses encoding/json as default json package, but you can change to jsoniter by build from other tags.

$ go build -tags=jsoniter .

Build without

render uses msg,protobuf,yaml, you can build without them with tags.

   $ go build -tags=noprotopack,noyamlpack,nomsgpack .

References

Documentation

Overview

Package render render for net/http

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsciiJSON

func AsciiJSON(w http.ResponseWriter, code int, obj interface{})

AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. It also sets the Content-Type as "application/json".

func Attachment

func Attachment(w http.ResponseWriter, filename string, data []byte)

Attachment attachment application/octet-stream;charset=utf-8

func Data

func Data(w http.ResponseWriter, code int, contentType string, data []byte)

Data writes some data into the body stream and updates the HTTP code.

func DataFromReader

func DataFromReader(w http.ResponseWriter, code int,
	contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string)

DataFromReader writes the specified reader into the body stream and updates the HTTP code.

func HTML

func HTML(w http.ResponseWriter, code int, name string, tpl *template.Template, obj interface{})

HTML renders the HTTP template specified by its file name. It also updates the HTTP code and sets the Content-Type as "text/html". See http://golang.org/doc/articles/wiki/

func IndentedJSON

func IndentedJSON(w http.ResponseWriter, code int, obj interface{})

IndentedJSON serializes the given struct as pretty JSON (indented + endlines) into the response body. It also sets the Content-Type as "application/json". WARNING: we recommend to use this only for development purposes since printing pretty JSON is more CPU and bandwidth consuming. Use Context.JSON() instead.

func JSON

func JSON(w http.ResponseWriter, code int, obj interface{})

JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".

func JSONP

func JSONP(w http.ResponseWriter, r *http.Request, code int, obj interface{})

JSONP serializes the given struct as JSON into the response body. It add padding to response body to request data from a server residing in a different domain than the client. It also sets the Content-Type as "application/javascript".

func MsgPack

func MsgPack(w http.ResponseWriter, code int, obj interface{})

MsgPack serializes the given struct as Msgpack into the response body.

func ProtoBuf

func ProtoBuf(w http.ResponseWriter, code int, obj interface{})

ProtoBuf serializes the given struct as ProtoBuf into the response body.

func PureJSON

func PureJSON(w http.ResponseWriter, code int, obj interface{})

PureJSON serializes the given struct as JSON into the response body. PureJSON, unlike JSON, does not replace special html characters with their unicode entities.

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, code int, location string)

Redirect returns a HTTP redirect to the specific location.

func Render

func Render(w http.ResponseWriter, code int, r render.Render)

Render render

func SecureJSON

func SecureJSON(w http.ResponseWriter, code int, obj interface{})

SecureJSON serializes the given struct as Secure JSON into the response body. Default prepends "while(1)," to response body if the given struct is array values. It also sets the Content-Type as "application/json".

func String

func String(w http.ResponseWriter, code int, format string, values ...interface{})

String writes the given string into the response body.

func XML

func XML(w http.ResponseWriter, code int, obj interface{})

XML serializes the given struct as XML into the response body. It also sets the Content-Type as "application/xml".

func YAML

func YAML(w http.ResponseWriter, code int, obj interface{})

YAML serializes the given struct as YAML into the response body.

Types

type H

type H map[string]interface{}

H is map[string]interface{}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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