Documentation ¶
Overview ¶
Package representation provides implementations that define representations and how to interact with them.
See Also ¶
Index ¶
- Constants
- Variables
- type Base
- func (r Base) Bytes(out interface{}) ([]byte, error)
- func (r Base) ContentCharset() string
- func (r Base) ContentEncoding() []string
- func (r Base) ContentFeatures() []string
- func (r Base) ContentLanguage() string
- func (r Base) ContentLocation() url.URL
- func (r Base) ContentType() string
- func (r Base) FromBytes(b []byte, in interface{}) (err error)
- func (r *Base) SetContentCharset(cc string)
- func (r *Base) SetContentEncoding(ce []string)
- func (r *Base) SetContentFeatures(cf []string)
- func (r *Base) SetContentLanguage(cl string)
- func (r *Base) SetContentLocation(l url.URL)
- func (r *Base) SetContentType(ct string)
- func (r *Base) SetEncodingReaders(e map[string]EncodingReaderConstructor)
- func (r *Base) SetEncodingWriters(e map[string]EncodingWriterConstructor)
- func (r *Base) SetMarshallers(m map[string]Marshaller)
- func (r *Base) SetSourceQuality(sq float32)
- func (r *Base) SetUnmarshallers(u map[string]Unmarshaller)
- func (r Base) SourceQuality() float32
- type Chooser
- type EncodingReaderConstructor
- type EncodingWriterConstructor
- type List
- type ListConstructor
- type Marshaller
- type Metadata
- type Predicate
- type RankedRepresentation
- type Representation
- type Set
- type Unmarshaller
Constants ¶
const ( // SourceQualityPerfect indicates that the representation is perfect // quality with no degradation. SourceQualityPerfect float32 = 1.0 // SourceQualityNearlyPerfect indicates the threshold of noticeable loss // of quality for the representation. SourceQualityNearlyPerfect float32 = 0.9 // SourceQualityAcceptable indicates that the representation has // noticeable but acceptable quality reduction. SourceQualityAcceptable float32 = 0.8 // SourceQualityBarelyAcceptable indicates that the representation // has barely acceptable quality. SourceQualityBarelyAcceptable float32 = 0.5 // SourceQualitySeverelyDegraded indicates that the representation // has severely degraded quality. SourceQualitySeverelyDegraded float32 = 0.3 // SourceQualityCompletelyDegraded indicates that the representation // has completed degraded quality. SourceQualityCompletelyDegraded float32 = 0.0 )
Source quality guidelines as defined in RFC2295 Section 5.3.
Variables ¶
var ( // ErrUnsupportedContentEncoding indicates an error that occurs when the // represention is given an unsupported content encoding. ErrUnsupportedContentEncoding = errors.New("representation content encoding is not supported") // ErrUnsupportedContentType indicates an error that occurs when the // represention is given an unsupported content type. ErrUnsupportedContentType = errors.New("representation content type is not supported") )
Errors that can be encountered when serializing and deserializing representations.
var ( // EmptySet is an empty representation set. EmptySet = Set([]RankedRepresentation{}) )
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the base representation.
func (Base) ContentCharset ¶
ContentCharset retrieves the content charset of the representation.
func (Base) ContentEncoding ¶
ContentEncoding retrieves the content encoding of the representation.
func (Base) ContentFeatures ¶
ContentFeatures retrieves the content features of the representation.
func (Base) ContentLanguage ¶
ContentLanguage retrieves the content language of the representation.
func (Base) ContentLocation ¶
ContentLocation retrieves the content location of the representation.
func (Base) ContentType ¶
ContentType retrieves the content type of the representation.
func (*Base) SetContentCharset ¶
SetContentCharset modifies the content charset of the representation.
func (*Base) SetContentEncoding ¶
SetContentEncoding modifies the content encoding of the representation.
func (*Base) SetContentFeatures ¶
SetContentFeatures retrieves the content features of the representation.
func (*Base) SetContentLanguage ¶
SetContentLanguage modifies the content language of the representation.
func (*Base) SetContentLocation ¶
SetContentLocation modifies the content location of the representation.
func (*Base) SetContentType ¶
SetContentType modifies the content type of the representation.
func (*Base) SetEncodingReaders ¶
func (r *Base) SetEncodingReaders(e map[string]EncodingReaderConstructor)
SetEncodingReaders modifies the encoding readers for the representation.
func (*Base) SetEncodingWriters ¶
func (r *Base) SetEncodingWriters(e map[string]EncodingWriterConstructor)
SetEncodingWriters modifies the encoding writers for the representation.
func (*Base) SetMarshallers ¶
func (r *Base) SetMarshallers(m map[string]Marshaller)
SetMarshallers modifies the marshallers for the representation.
func (*Base) SetSourceQuality ¶
SetSourceQuality modifies the source quality of the representation.
func (*Base) SetUnmarshallers ¶
func (r *Base) SetUnmarshallers(u map[string]Unmarshaller)
SetUnmarshallers modifies the unmarshallers for the representation.
func (Base) SourceQuality ¶
SourceQuality retrieves the source quality of the representation.
type Chooser ¶
type Chooser interface {
Choose(*http.Request, ...Representation) (Representation, error)
}
Chooser determines the 'best' representation from the provided set.
type EncodingReaderConstructor ¶
type EncodingReaderConstructor func(io.Reader) (io.ReadCloser, error)
EncodingReaderConstructor represents a constructor for closeable encoding readers.
type EncodingWriterConstructor ¶
type EncodingWriterConstructor func(io.WriteCloser) (io.WriteCloser, error)
EncodingWriterConstructor represents a constructor for closeable encoding writers.
type List ¶ added in v0.2.0
List represents a representation containing a list of descriptions of representations for a particular resource.
func (*List) FromBytes ¶ added in v0.2.0
FromBytes constructs the list representation from its serialized form.
func (*List) SetRepresentations ¶ added in v0.2.0
func (l *List) SetRepresentations(reps ...Representation)
SetRepresentations modifies the represention list within the list representation.
type ListConstructor ¶
type ListConstructor func(...Representation) Representation
ListConstructor represents a constructor function for the list representation returned to user agents.
type Marshaller ¶
Marshaller represents a marshaling function.
type Metadata ¶ added in v0.2.0
type Metadata struct { ContentType string `json:"contentType,omitempty"` ContentLanguage string `json:"contentLanguage,omitempty"` ContentEncoding []string `json:"contentEncoding,omitempty"` ContentLocation string `json:"contentLocation,omitempty"` ContentCharset string `json:"contentCharset,omitempty"` ContentFeatures []string `json:"contentFeatures,omitempty"` SourceQuality float32 `json:"sourceQuality"` }
RepresentationMetadata is the metadata about each representation in the representation list.
type Predicate ¶
type Predicate func(RankedRepresentation) bool
Predicate represents a matching function leveraged when filtering the representation set.
type RankedRepresentation ¶
type RankedRepresentation struct { Representation SourceQualityValue float32 MediaTypeQualityValue float32 CharsetQualityValue float32 LanguageQualityValue float32 EncodingQualityValue float32 FeatureQualityValue float32 IsDefinite bool LanguageOrderScore int }
RankedRepresentation is a representation that has been scored based on various dimensions utilized in server-side negotiation algorithms.
type Representation ¶
type Representation interface { ContentLocation() url.URL ContentType() string ContentEncoding() []string ContentCharset() string ContentLanguage() string ContentFeatures() []string SourceQuality() float32 Bytes() ([]byte, error) FromBytes([]byte) error }
Representation is an HTTP resource representation.
For the purposes of HTTP, a "representation" is information that is intended to reflect a past, current, or desired state of a given resource, in a format that can be readily communicated via the protocol, and that consists of a set of representation metadata and a potentially unbounded stream of representation data.
type Set ¶
type Set []RankedRepresentation
Set represents a collection of representations.
func (Set) AsSlice ¶
func (s Set) AsSlice() []RankedRepresentation
AsSlice converts the representation set into a slice.
func (Set) First ¶
func (s Set) First() RankedRepresentation
First task the first element of the representation set. Must check if the set is empty prior to invoking.
type Unmarshaller ¶
Unmarshaller represents an unmarshaling function.