render

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2017 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

chi/render is experimental package

Please, note that the render pkg API might change.

Documentation

Index

Constants

View Source
const (
	ContentTypePlainText = iota
	ContentTypeHTML
	ContentTypeJSON
	ContentTypeXML
	ContentTypeEventStream
)

ContentTypes handled by this package.

Variables

View Source
var Bind = defaultBind

Functions

func Data

func Data(w http.ResponseWriter, r *http.Request, v []byte)

Data writes raw bytes to the response, setting the Content-Type as application/octet-stream.

func HTML

func HTML(w http.ResponseWriter, r *http.Request, v string)

HTML writes a string to the response, setting the Content-Type as text/html.

func JSON

func JSON(w http.ResponseWriter, r *http.Request, v interface{})

JSON marshals 'v' to JSON, automatically escaping HTML and setting the Content-Type as application/json.

func NewPresenter

func NewPresenter(conversionFuncs ...interface{}) *presenter

func NoContent

func NoContent(w http.ResponseWriter, r *http.Request)

NoContent returns a HTTP 204 "No Content" response.

func PlainText

func PlainText(w http.ResponseWriter, r *http.Request, v string)

PlainText writes a string to the response, setting the Content-Type as text/plain.

func Respond

func Respond(w http.ResponseWriter, r *http.Request, v interface{})

Respond handles streaming JSON and XML responses, automatically setting the Content-Type based on request headers. It will default to a JSON response.

func SetContentType

func SetContentType(contentType ContentType) func(next http.Handler) http.Handler

SetContentType is a middleware that forces response Content-Type.

func Status

func Status(r *http.Request, status int)

Status sets status into request context.

func UsePresenter

func UsePresenter(p Presenter) func(next http.Handler) http.Handler

UsePresenter is a middleware that sets custom presenter into the context chain.

func XML

func XML(w http.ResponseWriter, r *http.Request, v interface{})

XML marshals 'v' to XML, setting the Content-Type as application/xml. It will automatically prepend a generic XML header (see encoding/xml.Header) if one is not found in the first 100 bytes of 'v'.

Types

type ContentType

type ContentType int

A ContentType is an enumeration of common HTTP content types.

type Presenter

type Presenter interface {
	Present(r *http.Request, from interface{}) (*http.Request, interface{})
}

Jump to

Keyboard shortcuts

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