echo4

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package echo4 provides adapters for easily using acceptable functions with Echo v4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BestRequestMatch

func BestRequestMatch(c echo.Context, available ...offer.Offer) *offer.Match

BestRequestMatch finds the content type and language that best matches the accepted media ranges and languages contained in request headers. The result contains the best match, based on the rules of RFC-7231. On exit, the result will contain the preferred language and charset, if these are known.

Whenever the result is nil, the response should be 406-Not Acceptable.

For all Ajax requests, the available offers are filtered so that only those capable of providing an Ajax response are considered by the content negotiation algorithm. The other offers are discarded.

The order of offers is important. It determines the order they are compared against the request headers, and it determines what defaults will be used when exact matching is not possible.

If no available offers are provided, the response will always be nil. Note too that Ajax requests will result in nil being returned if no offer is capable of handling them, even if other offers are provided.

func Binary

func Binary() offer.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

func CSV(comma ...rune) offer.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) offer.Processor

JSON creates a new processor for JSON with a specified indentation.

func RenderBestMatch

func RenderBestMatch(c echo.Context, template string, available ...offer.Offer) error

RenderBestMatch uses BestRequestMatch to find the best matching offer for the request, and then renders the response.

func TXT

func TXT() offer.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(root string, indent ...string) offer.Processor

XML creates a new processor for XML with root element and optional indentation. The root element is used only when processing content that is a sequence of data items.

Types

This section is empty.

Jump to

Keyboard shortcuts

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