Documentation
¶
Overview ¶
Package negotiate implements HTTP content negotiation for selecting request and response formats based on Accept and Content-Type headers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFormats ¶
DefaultFormats returns a format map with JSON registered under both "application/json" and "json" content types.
func DefaultJSONFormat ¶
DefaultJSONFormat returns a Format that uses the standard library JSON encoder and decoder with HTML escaping disabled.
func SelectQValue ¶
SelectQValue parses an Accept header and returns the allowed content type with the highest quality value. It returns an empty string if no match is found.
func SelectQValueFast ¶
SelectQValueFast is an optimized version of SelectQValue that avoids allocations by scanning the header in a single pass.
Types ¶
type Negotiator ¶
type Negotiator struct {
// contains filtered or unexported fields
}
Negotiator selects the appropriate format for marshalling and unmarshalling based on HTTP content type headers.
func NewNegotiator ¶
func NewNegotiator(formats map[string]core.Format, defaultFormat string, noFallback bool) *Negotiator
NewNegotiator creates a Negotiator with the given format map, default content type, and fallback behavior. When noFallback is true, unrecognized Accept values produce an error instead of falling back to the default format.
func (*Negotiator) Marshal ¶
Marshal encodes the value v into the writer using the format associated with the given content type.