package render
import "github.com/go-chi/chi/render"
Index ¶
- Constants
- Variables
- func Data(w http.ResponseWriter, r *http.Request, v []byte)
- func HTML(w http.ResponseWriter, r *http.Request, v string)
- func JSON(w http.ResponseWriter, r *http.Request, v interface{})
- func NewPresenter(conversionFuncs ...interface{}) *presenter
- func NoContent(w http.ResponseWriter, r *http.Request)
- func PlainText(w http.ResponseWriter, r *http.Request, v string)
- func Respond(w http.ResponseWriter, r *http.Request, v interface{})
- func SetContentType(contentType ContentType) func(next http.Handler) http.Handler
- func Status(r *http.Request, status int)
- func UsePresenter(p Presenter) func(next http.Handler) http.Handler
- func XML(w http.ResponseWriter, r *http.Request, v interface{})
- type ContentType
- type Presenter
Constants ¶
const ( ContentTypePlainText = iota ContentTypeHTML ContentTypeJSON ContentTypeXML ContentTypeEventStream )
ContentTypes handled by this package.
Variables ¶
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 ¶
Status sets status into request context.
func UsePresenter ¶
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{}) }
Source Files ¶
bind.go content_type.go presenter.go render.go status.go
- Version
- v2.0.0+incompatible
- Published
- Jan 6, 2017
- Platform
- js/wasm
- Imports
- 10 packages
- Last checked
- 4 days ago –
Tools for package owners.