Documentation ¶
Index ¶
- Variables
- func MakeErrorEncoder(codec Codec) kithttp.ErrorEncoder
- func MakeResponseEncoder(codec Codec, statusCode int) kithttp.EncodeResponseFunc
- type BasicParam
- type Bodier
- type Codec
- type Codecs
- type DefaultCodecs
- type Error
- type FailureResponse
- type FormFile
- type JSON
- func (j JSON) DecodeFailureResponse(body io.ReadCloser, out *error) error
- func (j JSON) DecodeRequestBody(r *http.Request, out interface{}) error
- func (j JSON) DecodeRequestParam(name string, values []string, out interface{}) error
- func (j JSON) DecodeRequestParams(name string, values map[string][]string, out interface{}) error
- func (j JSON) DecodeSuccessResponse(body io.ReadCloser, out interface{}) error
- func (j JSON) EncodeFailureResponse(w http.ResponseWriter, err error) error
- func (j JSON) EncodeRequestBody(body interface{}) (io.Reader, map[string]string, error)
- func (j JSON) EncodeRequestParam(name string, value interface{}) []string
- func (j JSON) EncodeRequestParams(name string, value interface{}) map[string][]string
- func (j JSON) EncodeSuccessResponse(w http.ResponseWriter, statusCode int, body interface{}) error
- type MultipartForm
- type NamedCodec
- type ParamCodec
- type ParamsCodec
- type Patcher
- func (p *Patcher) DecodeRequestParam(name string, values []string, out interface{}) error
- func (p *Patcher) DecodeRequestParams(name string, values map[string][]string, out interface{}) error
- func (p *Patcher) EncodeRequestParam(name string, value interface{}) []string
- func (p *Patcher) EncodeRequestParams(name string, value interface{}) map[string][]string
- func (p *Patcher) Param(name string, pc ParamCodec) *Patcher
- func (p *Patcher) Params(name string, psc ParamsCodec) *Patcher
- type StructParams
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnsupportedType = errors.New("unsupported type")
)
Functions ¶
func MakeErrorEncoder ¶
func MakeErrorEncoder(codec Codec) kithttp.ErrorEncoder
func MakeResponseEncoder ¶
func MakeResponseEncoder(codec Codec, statusCode int) kithttp.EncodeResponseFunc
Types ¶
type BasicParam ¶
type BasicParam struct{}
BasicParam is a built-in implementation of ParamCodec. It is mainly used to encode and decode a basic value or a slice of basic values.
func (BasicParam) Decode ¶
func (p BasicParam) Decode(in []string, out interface{}) error
Decode decodes a string slice to a basic value (or a slice of basic values).
func (BasicParam) Encode ¶
func (p BasicParam) Encode(in interface{}) (out []string)
Encode encodes a basic value (or a slice of basic values) to a string slice.
type Codec ¶
type Codec interface { // Encoders and decoders used at the server side. DecodeRequestParam(name string, values []string, out interface{}) error DecodeRequestParams(name string, values map[string][]string, out interface{}) error DecodeRequestBody(r *http.Request, out interface{}) error EncodeSuccessResponse(w http.ResponseWriter, statusCode int, body interface{}) error EncodeFailureResponse(w http.ResponseWriter, err error) error // Encoders and decoders used at the client side. EncodeRequestParam(name string, value interface{}) []string EncodeRequestParams(name string, value interface{}) map[string][]string EncodeRequestBody(body interface{}) (io.Reader, map[string]string, error) DecodeSuccessResponse(body io.ReadCloser, out interface{}) error DecodeFailureResponse(body io.ReadCloser, out *error) error }
Codec is a series of codecs (encoders and decoders) for HTTP requests and responses.
type DefaultCodecs ¶
func NewDefaultCodecs ¶
func NewDefaultCodecs(d Codec, namedCodecs ...NamedCodec) *DefaultCodecs
func (*DefaultCodecs) EncodeDecoder ¶
func (dc *DefaultCodecs) EncodeDecoder(name string) Codec
func (*DefaultCodecs) PatchAll ¶
func (dc *DefaultCodecs) PatchAll(patch func(Codec) *Patcher) *DefaultCodecs
PatchAll patches the default codec and all the custom codecs.
type FailureResponse ¶
type FailureResponse struct {
Error Error `json:"error"`
}
type FormFile ¶
FormFile describes a file part of a multipart message.
func FromMultipartFileHeader ¶
func FromMultipartFileHeader(fh *multipart.FileHeader) (*FormFile, error)
func FromOSFile ¶
type JSON ¶
type JSON struct{}
func (JSON) DecodeFailureResponse ¶
func (j JSON) DecodeFailureResponse(body io.ReadCloser, out *error) error
func (JSON) DecodeRequestBody ¶
func (JSON) DecodeRequestParam ¶
func (JSON) DecodeRequestParams ¶
func (JSON) DecodeSuccessResponse ¶
func (j JSON) DecodeSuccessResponse(body io.ReadCloser, out interface{}) error
func (JSON) EncodeFailureResponse ¶
func (j JSON) EncodeFailureResponse(w http.ResponseWriter, err error) error
func (JSON) EncodeRequestBody ¶
func (JSON) EncodeRequestParam ¶
func (JSON) EncodeRequestParams ¶
func (JSON) EncodeSuccessResponse ¶
func (j JSON) EncodeSuccessResponse(w http.ResponseWriter, statusCode int, body interface{}) error
type MultipartForm ¶
type MultipartForm struct { JSON // contains filtered or unexported fields }
func NewMultipartForm ¶
func NewMultipartForm(maxMemory int64) *MultipartForm
func (*MultipartForm) DecodeRequestBody ¶
func (mf *MultipartForm) DecodeRequestBody(r *http.Request, out interface{}) error
func (*MultipartForm) EncodeRequestBody ¶
type NamedCodec ¶
NamedCodec holds a codec and its corresponding operation name.
func Op ¶
func Op(name string, codec Codec) NamedCodec
Op is a shortcut for creating an instance of NamedCodec.
type ParamCodec ¶
type ParamCodec interface { Decode(in []string, out interface{}) error Encode(in interface{}) (out []string) }
ParamCodec is a codec (encoder and decoder) for a single request parameter.
type ParamsCodec ¶
type ParamsCodec interface { Decode(in map[string][]string, out interface{}) error Encode(in interface{}) (out map[string][]string) }
ParamsCodec is a codec (encoder and decoder) for a group of request parameters.
func ToParamsCodec ¶
func ToParamsCodec(codec ParamCodec) ParamsCodec
ToParamsCodec creates a ParamsCodec from a ParamCodec. It is mainly used along with StructParams.
type Patcher ¶
type Patcher struct { Codec // the original Codec // contains filtered or unexported fields }
Patcher is used to change the encoding and decoding behaviors of an existing instance of Codec.
func NewPatcher ¶
func (*Patcher) DecodeRequestParam ¶
func (*Patcher) DecodeRequestParams ¶
func (*Patcher) EncodeRequestParam ¶
func (*Patcher) EncodeRequestParams ¶
type StructParams ¶
type StructParams struct { Fields map[string]ParamsCodec // contains filtered or unexported fields }
StructParams is a built-in implementation of ParamsCodec. It is mainly used to encode and decode a struct. The encoding and decoding of each field can be customized by setting Fields.
func (StructParams) CamelCase ¶
func (p StructParams) CamelCase() StructParams
func (StructParams) Decode ¶
func (p StructParams) Decode(in map[string][]string, out interface{}) error
Decode decodes a string map to a struct (or a *struct).
func (StructParams) Encode ¶
func (p StructParams) Encode(in interface{}) (out map[string][]string)
Encode encodes a struct (or a *struct) to a string map.