render package - github.com/go-chi/render - Go Packages
- Variables
- func Bind(r *http.Request, v Binder) error
- func Data(w http.ResponseWriter, r *http.Request, v []byte)
- func DecodeForm(r io.Reader, v interface{}) error
- func DecodeJSON(r io.Reader, v interface{}) error
- func DecodeXML(r io.Reader, v interface{}) error
- func DefaultDecoder(r *http.Request, v interface{}) error
- func DefaultResponder(w http.ResponseWriter, r *http.Request, v interface{})
- func HTML(w http.ResponseWriter, r *http.Request, v string)
- func JSON(w http.ResponseWriter, r *http.Request, v interface{})
- func NoContent(w http.ResponseWriter, r *http.Request)
- func PlainText(w http.ResponseWriter, r *http.Request, v string)
- func Render(w http.ResponseWriter, r *http.Request, v Renderer) error
- func RenderList(w http.ResponseWriter, r *http.Request, l []Renderer) error
- func SetContentType(contentType ContentType) func(next http.Handler) http.Handler
- func Status(r *http.Request, status int)
- func XML(w http.ResponseWriter, r *http.Request, v interface{})
- type Binder
- type ContentType
- type M
- type Renderer
This section is empty.
var (
ContentTypeCtxKey = &contextKey{"ContentType"}
)
Decode is a package-level variable set to our default Decoder. We do this because it allows you to set render.Decode to another function with the same function signature, while also utilizing the render.Decoder() function itself. Effectively, allowing you to easily add your own logic to the package defaults. For example, maybe you want to impose a limit on the number of bytes allowed to be read from the request body.
Respond is a package-level variable set to our default Responder. We do this because it allows you to set render.Respond to another function with the same function signature, while also utilizing the render.Responder() function itself. Effectively, allowing you to easily add your own logic to the package defaults. For example, maybe you want to test if v is an error and respond differently, or log something before you respond.
StatusCtxKey is a context key to record a future HTTP response status code.
Bind decodes a request body and executes the Binder method of the payload structure.
Data writes raw bytes to the response, setting the Content-Type as application/octet-stream.
DecodeForm decodes a given reader into an interface using the form decoder.
DecodeJSON decodes a given reader into an interface using the json decoder.
DecodeXML decodes a given reader into an interface using the xml decoder.
DefaultDecoder detects the correct decoder for use on an HTTP request and marshals into a given interface.
Respond handles streaming JSON and XML responses, automatically setting the Content-Type based on request headers. It will default to a JSON response.
HTML writes a string to the response, setting the Content-Type as text/html.
JSON marshals 'v' to JSON, automatically escaping HTML and setting the Content-Type as application/json.
PlainText writes a string to the response, setting the Content-Type as text/plain.
Render renders a single payload and respond to the client request.
RenderList renders a slice of payloads and responds to the client request.
func SetContentType ¶
SetContentType is a middleware that forces response Content-Type.
Status sets a HTTP response status code hint into request context at any point during the request life-cycle. Before the Responder sends its response header it will check the StatusCtxKey
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'.
Binder interface for managing request payloads.
type ContentType ¶
ContentType is an enumeration of common HTTP content types.
const ( ContentTypeUnknown ContentType = iota ContentTypePlainText ContentTypeHTML ContentTypeJSON ContentTypeXML ContentTypeForm ContentTypeEventStream )
ContentTypes handled by this package.
func GetRequestContentType ¶
GetRequestContentType is a helper function that returns ContentType based on context or request headers.
M is a convenience alias for quickly building a map structure that is going out to a responder. Just a short-hand.
Renderer interface for managing response payloads.