Documentation ¶
Index ¶
- Constants
- Variables
- func GetErrorInstance(s string) (interface{}, error)
- func MakeErrorEncoder(gen RequestResponseEncoding) httptransport.ErrorEncoder
- func MakeRequestDecoder(request interface{}, gen GenerateDecoder) httptransport.DecodeRequestFunc
- func MakeRequestEncoder(gen GenerateEncoder) httptransport.EncodeRequestFunc
- func MakeResponseDecoder(response interface{}, gen GenerateDecoder) httptransport.DecodeResponseFunc
- func MakeResponseEncoder(gen GenerateEncoder) httptransport.EncodeResponseFunc
- func Register(mime string, encoding RequestResponseEncoding, startHint []rune) error
- func RegisterError(e error) error
- type Decoder
- type EmbededMime
- type Encoder
- type Err
- type GenerateDecoder
- type GenerateEncoder
- type Gob
- type JSON
- type RequestResponseEncoding
- type WrapperError
- type XML
Constants ¶
const DefaultEncoding = "application/json"
Variables ¶
var ErrBlacklisted = errors.New("This Error type isn't able to registered, as it is not encodable / decodable")
var ErrDuplicate = errors.New("You tried to register a duplicate type")
var ErrEmptyRequest = errors.New("Empty Request, nothing to sniff")
var ErrUnexpectedElementType = errors.New("Unexpected XML Element Type")
var ErrUnexpectedJSONDelim = errors.New("Unexpected JSON Delim")
var ErrUnknownError = errors.New("The type specified hasn't be registered")
Functions ¶
func GetErrorInstance ¶
GetErrorInstance will use reflection to attempt and instanciate a new error of the given type string. The error returned will be a pointer.
func MakeErrorEncoder ¶
func MakeErrorEncoder(gen RequestResponseEncoding) httptransport.ErrorEncoder
MakeErrorEncoder will take a generic GenerateEncoder function and will return an ErrorEncoder
func MakeRequestDecoder ¶
func MakeRequestDecoder(request interface{}, gen GenerateDecoder) httptransport.DecodeRequestFunc
MakeRequestDecoder exists to help bridge the gaps for encoding. It takes a request interface type, and a GenerateDecoder, and ultimately returns a function that can decode the given request.
func MakeRequestEncoder ¶
func MakeRequestEncoder(gen GenerateEncoder) httptransport.EncodeRequestFunc
MakeRequestEncoder takes a GenerateEncoder and returns an httptransport.EncodeRequestFunc
func MakeResponseDecoder ¶
func MakeResponseDecoder(response interface{}, gen GenerateDecoder) httptransport.DecodeResponseFunc
MakeResponseDecoder exists to help bridge the gaps for encoding. It takes a response interface type, and a GenerateDecoder, and ultimately returns a function that can decode a given Response.
func MakeResponseEncoder ¶
func MakeResponseEncoder(gen GenerateEncoder) httptransport.EncodeResponseFunc
MakeResponseEncoder takes a GenerateEncoder and returns an httpstransport.EncodeResponseFunc
func Register ¶
func Register(mime string, encoding RequestResponseEncoding, startHint []rune) error
Register will register the associated encoding with the given mime type
func RegisterError ¶
RegisterError will attempt to register the given Error with the encoders / decoders and will make it available for Decoding errors for the encoders / decoders.
This will not automatically register this error type with encoding/gob
Types ¶
type Decoder ¶
type Decoder interface { // Decode should populate the given interface with the information stored // within the Decoder. Decode(interface{}) error }
Decoder is any type that can populate a given structure via a Decode method.
func GobGenerateDecoder ¶
GobGenerateDecoder returns a GOB Decoder
func JSONGenerateDecoder ¶
JSONGenerateDecoder returns a JSON Decoder
func XMLGenerateDecoder ¶
XMLGenerateDecoder returns an XML Decoder
type EmbededMime ¶
type EmbededMime interface { // Retrieves the currently set mime type of this structure. If nothing has // been set, it would be best to specify a def one. GetMime() string // Sets the current mime type to use. If set this mime type should be // retrieved by future calls to GetMime on the same variable. SetMime(mime string) }
EmbededMime applies to the intermediary transmission representation of method arguments and results. Using the structure we will attempt to communicate with the encoders / decoders what mime type to use.
type Encoder ¶
type Encoder interface { // Encode takes an interface, and should be able to translate it within the // given encoding, or it will fail with an error. Encode(interface{}) error }
Encoder is anything that, given an interface, can store an encoding of the structure passed into Encode.
func GobGenerateEncoder ¶
GobGenerateEncoder returns a GOB Encoder
func JSONGenerateEncoder ¶
JSONGenerateEncoder returns a JSON Encoder
func XMLGenerateEncoder ¶
XMLGenerateEncoder returns an XML Encoder
type Err ¶
type Err int
Err are the errors that can be returned from Register or Get
const ( // ErrUnknown represents a non-error ErrUnknown Err = iota // ErrAlreadyRegistered represents an mime type that has already been // registered ErrAlreadyRegistered // ErrMimeNotFound represents a mime type with no associated encoding ErrMimeNotFound // ErrNoRegistrationsExist represents that nothing has been registered with // this Encoder / Decoder ErrNoRegistrationsExist // ErrMimeNotSpecified rerpesents that no information has been specified // in order to determine the Mime-type ErrMimeNotSpecified // ErrUnableToDetermineMime represents an error that indicates that // the attempt to automatically detect the mime type has failed. ErrUnableToDetermineMime // ErrNotImplemented represents that the functionality of this method is // not implemented. ErrNotImplemented )
type GenerateDecoder ¶
GenerateDecoder is a function that takes an io.Reader and returns a Decoder
type GenerateEncoder ¶
GenerateEncoder is a function which takes an io.Writer, and returns an Encoder
type Gob ¶
type Gob int
Gob is a simple Gob encoder / decoder that conforms to RequestResponseEncoding
func (Gob) DecodeRequest ¶
func (Gob) DecodeRequest(request interface{}) httptransport.DecodeRequestFunc
DecodeRequest implements RequestResponseEncoding
func (Gob) DecodeResponse ¶
func (Gob) DecodeResponse(response interface{}) httptransport.DecodeResponseFunc
DecodeResponse implements RequestResponseEncoding
func (Gob) EncodeRequest ¶
func (Gob) EncodeRequest() httptransport.EncodeRequestFunc
EncodeRequest implements RequestResponseEncoding
func (Gob) EncodeResponse ¶
func (Gob) EncodeResponse() httptransport.EncodeResponseFunc
EncodeResponse implements RequestResponseEncoding
type JSON ¶
type JSON int
JSON is a simple JSON encoder / decoder that conforms to RequestResponseEncoding
func (JSON) DecodeRequest ¶
func (JSON) DecodeRequest(request interface{}) httptransport.DecodeRequestFunc
DecodeRequest implements RequestResponseEncoding
func (JSON) DecodeResponse ¶
func (JSON) DecodeResponse(response interface{}) httptransport.DecodeResponseFunc
DecodeResponse implements RequestResponseEncoding
func (JSON) EncodeRequest ¶
func (JSON) EncodeRequest() httptransport.EncodeRequestFunc
EncodeRequest implements RequestResponseEncoding
func (JSON) EncodeResponse ¶
func (JSON) EncodeResponse() httptransport.EncodeResponseFunc
EncodeResponse implements RequestResponseEncoding
type RequestResponseEncoding ¶
type RequestResponseEncoding interface { // EncodeRequest should be able to return an EncodeRequestFunc that can // encode the given requests with the encoding type represented by this // type. EncodeRequest() httptransport.EncodeRequestFunc // DecodeRequest should be able to return a DecodeRequestFunc that, when // provided with an underlying type, can be used to decode a request with // the encoding type represented by this type. DecodeRequest(request interface{}) httptransport.DecodeRequestFunc // EncodeResponse should be able to return an EncodeResponseFunc that can // encode a given response with the encoding type represented by this // type. EncodeResponse() httptransport.EncodeResponseFunc // DecodeResponse should be able to return a DecodeResponseFunc that, when // provided with an underlying type, can be used to decode a response with // the encoding type represented by this type. DecodeResponse(response interface{}) httptransport.DecodeResponseFunc }
RequestResponseEncoding represents a type that can be used to automatically Encode and Decode on HTTP requests used by files generated with go-kit-middlewarer
func Default ¶
func Default() RequestResponseEncoding
Default returns the default RequestResponseEncoding
func Get ¶
func Get(mime string) (RequestResponseEncoding, error)
Get will retrieve the encoding registered with the mime-type
type WrapperError ¶
type WrapperError struct { Type string `json:"type" xml:"type"` ErrString string `json:"errorString" xml:"error-string"` Err interface{} `json:"error" xml:"error"` }
func WrapError ¶
func WrapError(e error) *WrapperError
func (WrapperError) Error ¶
func (we WrapperError) Error() string
func (*WrapperError) UnmarshalJSON ¶
func (we *WrapperError) UnmarshalJSON(p []byte) error
implements encoding/json.Unmarshaler
func (*WrapperError) UnmarshalXML ¶
func (we *WrapperError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
implements encoding/xml.Unmarshaler
type XML ¶
type XML int
XML is a simple XML encoder / decoder that conforms to RequestResponseEncoding
func (XML) DecodeRequest ¶
func (XML) DecodeRequest(request interface{}) httptransport.DecodeRequestFunc
DecodeRequest implements RequestResponseEncoding
func (XML) DecodeResponse ¶
func (XML) DecodeResponse(response interface{}) httptransport.DecodeResponseFunc
DecodeResponse implements RequestResponseEncoding
func (XML) EncodeRequest ¶
func (XML) EncodeRequest() httptransport.EncodeRequestFunc
EncodeRequest implements RequestResponseEncoding
func (XML) EncodeResponse ¶
func (XML) EncodeResponse() httptransport.EncodeResponseFunc
EncodeResponse implements RequestResponseEncoding