representation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package representation provides implementations that define representations and how to interact with them.

See Also

https://tools.ietf.org/html/rfc7231#section-3

https://tools.ietf.org/html/rfc2295#section-5.3

Index

Constants

View Source
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

View Source
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.

View Source
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) Bytes

func (r Base) Bytes(out interface{}) ([]byte, error)

Bytes retrieves the serialized form of the representation.

func (Base) ContentCharset

func (r Base) ContentCharset() string

ContentCharset retrieves the content charset of the representation.

func (Base) ContentEncoding

func (r Base) ContentEncoding() []string

ContentEncoding retrieves the content encoding of the representation.

func (Base) ContentFeatures

func (r Base) ContentFeatures() []string

ContentFeatures retrieves the content features of the representation.

func (Base) ContentLanguage

func (r Base) ContentLanguage() string

ContentLanguage retrieves the content language of the representation.

func (Base) ContentLocation

func (r Base) ContentLocation() url.URL

ContentLocation retrieves the content location of the representation.

func (Base) ContentType

func (r Base) ContentType() string

ContentType retrieves the content type of the representation.

func (Base) FromBytes

func (r Base) FromBytes(b []byte, in interface{}) (err error)

FromBytes constructs the representation from its serialized form.

func (*Base) SetContentCharset

func (r *Base) SetContentCharset(cc string)

SetContentCharset modifies the content charset of the representation.

func (*Base) SetContentEncoding

func (r *Base) SetContentEncoding(ce []string)

SetContentEncoding modifies the content encoding of the representation.

func (*Base) SetContentFeatures

func (r *Base) SetContentFeatures(cf []string)

SetContentFeatures retrieves the content features of the representation.

func (*Base) SetContentLanguage

func (r *Base) SetContentLanguage(cl string)

SetContentLanguage modifies the content language of the representation.

func (*Base) SetContentLocation

func (r *Base) SetContentLocation(l url.URL)

SetContentLocation modifies the content location of the representation.

func (*Base) SetContentType

func (r *Base) SetContentType(ct string)

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

func (r *Base) SetSourceQuality(sq float32)

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

func (r Base) SourceQuality() float32

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

type List struct {
	Base

	Representations []Metadata `json:"representations"`
}

List represents a representation containing a list of descriptions of representations for a particular resource.

func (List) Bytes added in v0.2.0

func (l List) Bytes() ([]byte, error)

Bytes retrieves the serialized form of the list representation.

func (*List) FromBytes added in v0.2.0

func (l *List) FromBytes(b []byte) error

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

type Marshaller func(interface{}) ([]byte, error)

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

Set represents a collection of representations.

func (Set) AsSlice

func (s Set) AsSlice() []RankedRepresentation

AsSlice converts the representation set into a slice.

func (Set) Empty

func (s Set) Empty() bool

Empty indicates if the representation set is empty.

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.

func (Set) Size

func (s Set) Size() int

Size provides the size of the representation set.

func (Set) Sort

func (s Set) Sort(less func(i, j int) bool)

Sort sorts the representation set based on the provided less function.

func (Set) Where

func (s Set) Where(p Predicate) Set

Where filters the representation set using the provided predicate.

type Unmarshaller

type Unmarshaller func([]byte, interface{}) error

Unmarshaller represents an unmarshaling function.

Jump to

Keyboard shortcuts

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