Documentation ¶
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 UsePresenter ¶
UsePresenter is a middleware that sets custom presenter into the context chain.
Types ¶
type ContentType ¶
type ContentType int
A ContentType is an enumeration of common HTTP content types.