processor

package
v0.10.0 Latest Latest
Warning

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

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

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

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 * 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.

Jump to

Keyboard shortcuts

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