Documentation ¶
Overview ¶
Package response provides functions for working with an http response.
Every write operation to the ResponseWriter returns the error behaviour WriteFailed.
TODO(cs) => github.com/streadway/handy
Index ¶
- type Print
- func (p Print) File(path, name string, attachment bool) error
- func (p Print) HTML(code int, format string, a ...interface{}) error
- func (p Print) JSON(code int, i interface{}) (err error)
- func (p Print) JSONIndent(code int, i interface{}, prefix string, indent string) (err error)
- func (p Print) JSONP(code int, callback string, i interface{}) error
- func (p Print) NoContent(code int) error
- func (p Print) Redirect(code int, url string) error
- func (p Print) Render(code int, name string, data interface{}) error
- func (p Print) String(code int, format string, a ...interface{}) error
- func (p Print) WriteString(code int, s string) error
- func (p Print) XML(code int, i interface{}) (err error)
- func (p Print) XMLIndent(code int, i interface{}, prefix string, indent string) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Print ¶
type Print struct { // FileSystem stubbed out for testing. Default http.Dir FileSystem http.FileSystem Response http.ResponseWriter Request *http.Request Renderer interface { // ExecuteTemplate is the interface function to text/template or html/template ExecuteTemplate(wr io.Writer, name string, data interface{}) error } }
Print is a helper type for outputting data to a ResponseWriter. Print act as a non-pointer type. Print functions uses internally a byte buffer pool.
func NewPrinter ¶
func NewPrinter(w http.ResponseWriter, r *http.Request) Print
NewPrinter creates a non-pointer printer
func (Print) File ¶
File sends a response with the content of the file. If `attachment` is set to true, the client is prompted to save the file with provided `name`, name can be empty, in that case name of the file is used.
func (Print) HTML ¶
HTML formats according to a format specifier and sends HTML response with status code.
func (Print) JSONIndent ¶
JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output.
func (Print) JSONP ¶
JSONP sends a JSONP response with status code. It uses `callback` to construct the JSONP payload.
func (Print) Render ¶
Render renders a template with data and sends a text/html response with status code. Templates can be registered during `Print` creation.
func (Print) String ¶
String formats according to a format specifier and sends text response with status code.
func (Print) WriteString ¶
WriteString converts a string into []bytes and outputs it. No formatting feature available.