processor

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package processor contains flexible implementations for rendering JSON, XML, CSV etc. A Render is defined as

type Render func(w http.ResponseWriter, match Match, template string, dataModel interface{}) error

Index

Constants

View Source
const JSONContentType = "application/json"
View Source
const TextCsv = "text/csv"
View Source
const TextPlain = "text/plain"
View Source
const XMLContentType = "application/xml"

Variables

View Source
var DefaultCSVOffer = acceptable.OfferOf(TextCsv).Using(CSV())

DefaultCSVOffer is an Offer for text/plain content using the CSV() processor.

View Source
var DefaultImageOffer = acceptable.OfferOf("image/*").Using(Binary())

DefaultImageOffer is an Offer for image/* content using the Binary() processor.

View Source
var DefaultJSONOffer = acceptable.OfferOf(JSONContentType).Using(JSON())

DefaultJSONOffer is an Offer for application/json content using the JSON() processor without indentation.

View Source
var DefaultTXTOffer = acceptable.OfferOf(TextPlain).Using(TXT())

DefaultTXTOffer is an Offer for text/plain content using the TXT() processor.

View Source
var DefaultXMLOffer = acceptable.OfferOf(XMLContentType).Using(XML())

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 * acceptable.Supplier function returning one of the above * 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).

* acceptable.Supplier function returning one of the above

func JSON

func JSON(indent ...string) acceptable.Processor

JSON creates a new processor for JSON with a specified indentation. If match.Data is an acceptable.Supplier function, it is used to provide the model data.

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

* acceptable.Supplier function returning one of the above

func XML

func XML(indent ...string) acceptable.Processor

XML creates a new processor for XML with optional indentation. If match.Data is an acceptable.Supplier function, it is used to provide the model data.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL