Documentation
¶
Overview ¶
Package processor contains flexible implementations for rendering JSON, XML, CSV and plain text.
An acceptable.Processor is defined as
type Processor func(w http.ResponseWriter, match Match, template string) error
Index ¶
Constants ¶
const JSONContentType = "application/json"
const TextCsv = "text/csv"
const TextPlain = "text/plain"
const XMLContentType = "application/xml"
Variables ¶
var DefaultCSVOffer = acceptable.OfferOf(CSV(), TextCsv)
DefaultCSVOffer is an Offer for text/plain content using the CSV() processor.
var DefaultImageOffer = acceptable.OfferOf(Binary(), "image/*")
DefaultImageOffer is an Offer for image/* content using the Binary() processor.
var DefaultJSONOffer = acceptable.OfferOf(JSON(), JSONContentType)
DefaultJSONOffer is an Offer for application/json content using the JSON() processor without indentation.
var DefaultTXTOffer = acceptable.OfferOf(TXT(), TextPlain)
DefaultTXTOffer is an Offer for text/plain content using the TXT() processor.
var DefaultXMLOffer = acceptable.OfferOf(XML(), XMLContentType)
DefaultXMLOffer is an Offer for application/xml content using the XML() processor without indentation.
Functions ¶
func Binary ¶ added in v0.6.0
func Binary() acceptable.Processor
Binary creates an output processor that outputs binary data in a form suitable for image/* and similar responses. Model values should be one of the following:
* []byte * io.Reader * nil
func CSV ¶ added in v0.6.0
func CSV(comma ...rune) acceptable.Processor
CSV creates an output processor that serialises a dataModel in CSV form. With no arguments, the default format is comma-separated; you can supply any rune to be used as an alternative separator.
Model values should be one of the following:
* string or []string, or [][]string
* fmt.Stringer or []fmt.Stringer, or [][]fmt.Stringer
* []int or similar (bool, int8, int16, int32, int64, uint8, uint16, uint32, uint63, float32, float64, complex)
* [][]int or similar (bool, int8, int16, int32, int64, uint8, uint16, uint32, uint63, float32, float64, complex)
* struct for some struct in which all the fields are exported and of simple types (as above).
* []struct for some struct in which all the fields are exported and of simple types (as above).
func JSON ¶
func JSON(indent ...string) acceptable.Processor
JSON creates a new processor for JSON with a specified indentation.
func TXT ¶
func TXT() acceptable.Processor
TXT creates an output processor that serialises strings in a form suitable for text/plain responses. Model values should be one of the following:
* string
* fmt.Stringer
* encoding.TextMarshaler
func XML ¶
func XML(indent ...string) acceptable.Processor
XML creates a new processor for XML with optional indentation.
Types ¶
This section is empty.