Documentation ¶
Overview ¶
Package offer provides the means to offer various permutations of data, content type and language to the content negotiation matching algorithm. It also provides Match, the result type from the matching algorithm.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Match ¶
type Match struct { Type string Subtype string Language string Charset string Vary []string Data data.Data Render Processor }
Match holds the best-matched offer after content negotiation and is used for response rendering.
func (Match) ApplyHeaders ¶
func (m Match) ApplyHeaders(rw http.ResponseWriter) io.Writer
ApplyHeaders sets response headers so that the user agent is notified of the content negotiation decisons made. Four headers may be set, depending on context.
- Content-Type is always set.
- Content-Language is set when a language was selected.
- Content-Encoding is set when the character set is being transcoded
- Vary is set to list the accept headers that led to the three decisions above.
type Offer ¶
type Offer struct { // ContentType is the content type that is to be matched. // Wildcard values may be used. header.ContentType // Langs lists the language(s) provided by this offer. Langs []string // contains filtered or unexported fields }
Offer holds information about one particular resource representation that can potentially provide an acceptable response.
func Of ¶
Of constructs an Offer easily, given a content type. If the content type is blank, it is assumed to be the full wildcard "*/*". Also, contentType can be a partial wildcard "type/*".
func (Offer) BuildMatch ¶
func (o Offer) BuildMatch(lang string, acceptedCT header.MediaRange) *Match
BuildMatch implements the transition between a selected Offer and the resulting Match.
func (Offer) With ¶
With attaches response data to an offer. The language parameter specifies what language (or language group) the offer will match. It can be "*" to match any. The method panics if it is blank. Other languages can also be specified, but these must not be "*" (or blank).
The data can be a value (struct, slice, etc) or a data.Data. It may also be nil, which means the method merely serves to add the language to the Offer's supported languages.
The original offer is unchanged.