Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var JSON = Generic(func(w io.Writer, data interface{}) error { enc := json.NewEncoder(w) enc.SetIndent("", " ") return enc.Encode(data) }, "application/json;charset=utf-8")
JSON serializes result object into JSON format
var TextXML = Generic(func(w io.Writer, data interface{}) error { return xml.NewEncoder(w).Encode(data) }, "text/xml;charset=utf-8")
TextXML is the same as XML, but with "text/xml" content type
var XML = Generic(func(w io.Writer, data interface{}) error { return xml.NewEncoder(w).Encode(data) }, "application/xml;charset=utf-8")
XML serializes result object into "application/xml" content type. Use TextXML for "text/xml" output.
Functions ¶
func ContentType ¶
ContentType creates renderer middleware that renders response to JSON, XML or HTML template based on Accept header. If Accept header is not specified, JSON is used as the output format. If nil is passed as template, only XML and JSON are rendered and text/html is output as JSON inside PRE tag.
func Generic ¶
func Generic(s SerializerFunc, contentType string) noodle.Middleware
Generic factory for a middleware that lifts handler's data object from context and serializes it into HTTP ResponseWriter. Receives SerializerFunc and content type
Types ¶
type SerializerFunc ¶
SerializerFunc is modelled after template's Execute method. Used by Generic middleware factory to create specific rendering middlewares