Version: v2.0.0+incompatible Latest Latest

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

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


chi/render is experimental package

Please, note that the render pkg API might change.




View Source
const (
	ContentTypePlainText = iota

ContentTypes handled by this package.


View Source
var Bind = defaultBind


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'.


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
t or T : Toggle theme light dark auto
y or Y : Canonical URL