Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithFactory(ctx context.Context, f Factory) context.Context
- func EachParameter(_ context.Context, t typesx.Type, each func(p *Param) bool)
- func EachReqParam(ctx context.Context, tpe typesx.Type, each func(rp *ReqParam)) error
- func GroupedParamSetFromContext(ctx context.Context) *sync.Map
- func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader
- func MustNewFileHeader(fieldName string, filename string, r io.Reader) *multipart.FileHeader
- func NewFactory() *factory
- func NewFileHeader(fieldName string, filename string, r io.Reader) (*multipart.FileHeader, error)
- func NewValidator(ctx context.Context, ft typesx.Type, tags map[string]reflectx.StructTag, ...) (validator.Validator, error)
- func ParamsFromMap(m map[string]string) httprouter.Params
- func ToPathParts(p string) []string
- func Transformers() (ret []string)
- func WithGroupedParamSet(ctx context.Context, m *sync.Map) context.Context
- func WrapLocationDecoderError(dec *json.Decoder, err error) error
- type CanInterface
- type CanNextReader
- type CanNextWriter
- type CanString
- type CommonOption
- type Factory
- type FileHeaderReader
- type FlattenParams
- type FormPartWriter
- type GroupedParams
- type HTMLText
- func (HTMLText) DecodeFrom(_ context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *HTMLText) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (HTMLText) NamedByTag() string
- func (HTMLText) Names() []string
- func (HTMLText) New(context.Context, typesx.Type) (Transformer, error)
- func (t *HTMLText) String() string
- type HeaderWriter
- type JSON
- func (JSON) DecodeFrom(ctx context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *JSON) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (JSON) NamedByTag() string
- func (JSON) Names() []string
- func (JSON) New(context.Context, typesx.Type) (Transformer, error)
- func (t *JSON) String() string
- type MayValidator
- type Multipart
- func (t *Multipart) DecodeFrom(ctx context.Context, r io.Reader, v interface{}, ...) error
- func (t *Multipart) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (Multipart) NamedByTag() string
- func (Multipart) Names() []string
- func (Multipart) New(ctx context.Context, typ typesx.Type) (Transformer, error)
- func (t *Multipart) String() string
- type OctetStream
- func (OctetStream) DecodeFrom(_ context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *OctetStream) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (OctetStream) Names() []string
- func (OctetStream) New(context.Context, typesx.Type) (Transformer, error)
- func (t *OctetStream) String() string
- type Option
- type Param
- type ParamAndValue
- type PartWriterCreator
- type PathWalker
- type PathnamePattern
- type PlainText
- func (t *PlainText) DecodeFrom(_ context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *PlainText) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (PlainText) Names() []string
- func (PlainText) New(context.Context, typesx.Type) (Transformer, error)
- func (t *PlainText) String() string
- type Protobuf
- func (t *Protobuf) DecodeFrom(ctx context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *Protobuf) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (Protobuf) NamedByTag() string
- func (Protobuf) Names() []string
- func (Protobuf) New(context.Context, typesx.Type) (Transformer, error)
- func (t *Protobuf) NewValidator(_ context.Context, _ typesx.Type) (validator.Validator, error)
- func (t *Protobuf) String() string
- type ReqParam
- type StringBuilders
- type StringReader
- type StringReaders
- type Super
- type Transformer
- type TsfmAndOption
- type URLEncoded
- func (t *URLEncoded) DecodeFrom(ctx context.Context, r io.Reader, v interface{}, ...) error
- func (t *URLEncoded) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (URLEncoded) NamedByTag() string
- func (URLEncoded) Names() []string
- func (URLEncoded) New(ctx context.Context, typ typesx.Type) (Transformer, error)
- func (t URLEncoded) String() string
- type WithNamedByTag
- type XML
- func (XML) DecodeFrom(_ context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
- func (t *XML) EncodeTo(ctx context.Context, w io.Writer, v interface{}) error
- func (XML) NamedByTag() string
- func (XML) Names() []string
- func (XML) New(context.Context, typesx.Type) (Transformer, error)
- func (t *XML) String() string
Constants ¶
View Source
const HTMLTsfName = "text/html"
Variables ¶
View Source
var ( ErrEncodeDataNotProtobuf = errors.New("encode data must be `proto.Message`") ErrDecodeTargetNotProtobuf = errors.New("decode target must be `proto.Message`") )
View Source
var DefaultFactory = &factory{}
Functions ¶
func EachReqParam ¶
func MIMEHeader ¶
func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader
func MustNewFileHeader ¶
func NewFactory ¶
func NewFactory() *factory
func NewFileHeader ¶
func NewValidator ¶
func ParamsFromMap ¶
func ParamsFromMap(m map[string]string) httprouter.Params
func ToPathParts ¶
func Transformers ¶
func Transformers() (ret []string)
Transformers returns all tsfms registered to DefaultFactory
func WithGroupedParamSet ¶
Types ¶
type CanInterface ¶
type CanInterface interface {
Interface() interface{}
}
type CanNextReader ¶
type CanNextWriter ¶
type CommonOption ¶
type Factory ¶
type Factory interface {
NewTransformer(context.Context, typesx.Type, Option) (Transformer, error)
}
func FactoryFromContext ¶
type FileHeaderReader ¶
type FileHeaderReader struct {
// contains filtered or unexported fields
}
func (*FileHeaderReader) Interface ¶
func (f *FileHeaderReader) Interface() interface{}
type FlattenParams ¶
type FlattenParams struct {
Params []ReqParam
}
func (*FlattenParams) CollectParams ¶
func (FlattenParams) NewValidator ¶
func (FlattenParams) String ¶
func (FlattenParams) String() string
func (*FlattenParams) Validate ¶
func (ps *FlattenParams) Validate(v interface{}) error
type FormPartWriter ¶
type FormPartWriter struct {
// contains filtered or unexported fields
}
func NewFormPartWriter ¶
func NewFormPartWriter(creator PartWriterCreator) *FormPartWriter
func (*FormPartWriter) Header ¶
func (w *FormPartWriter) Header() http.Header
func (*FormPartWriter) NextWriter ¶
func (w *FormPartWriter) NextWriter() io.Writer
type GroupedParams ¶
func CollectGroupedParam ¶
func CollectGroupedParam(ctx context.Context, tpe typesx.Type) GroupedParams
type HTMLText ¶
type HTMLText struct{}
func (HTMLText) DecodeFrom ¶
func (HTMLText) NamedByTag ¶
type HeaderWriter ¶
type HeaderWriter interface { httpx.WithHeader io.Writer }
func WriterWithHeader ¶
func WriterWithHeader(w io.Writer, header http.Header) HeaderWriter
type JSON ¶
type JSON struct{}
func (JSON) DecodeFrom ¶
func (JSON) NamedByTag ¶
type MayValidator ¶
type Multipart ¶
type Multipart struct{ *FlattenParams }
Multipart for multipart/form-data
func (*Multipart) DecodeFrom ¶
func (Multipart) NamedByTag ¶
type OctetStream ¶
type OctetStream struct{}
func (OctetStream) DecodeFrom ¶
func (OctetStream) DecodeFrom(_ context.Context, r io.Reader, v interface{}, _ ...textproto.MIMEHeader) error
func (OctetStream) Names ¶
func (OctetStream) Names() []string
func (OctetStream) New ¶
func (OctetStream) New(context.Context, typesx.Type) (Transformer, error)
func (*OctetStream) String ¶
func (t *OctetStream) String() string
type Option ¶
type Option struct { Name string MIME string CommonOption }
type Param ¶
type ParamAndValue ¶
type PartWriterCreator ¶
type PartWriterCreator func(header textproto.MIMEHeader) (io.Writer, error)
type PathWalker ¶
type PathWalker struct {
// contains filtered or unexported fields
}
func (*PathWalker) Enter ¶
func (p *PathWalker) Enter(i interface{})
func (*PathWalker) Exit ¶
func (p *PathWalker) Exit()
func (*PathWalker) Paths ¶
func (p *PathWalker) Paths() []interface{}
func (*PathWalker) String ¶
func (p *PathWalker) String() string
type PathnamePattern ¶
type PathnamePattern struct {
// contains filtered or unexported fields
}
func NewPathnamePattern ¶
func NewPathnamePattern(pattern string) *PathnamePattern
func (*PathnamePattern) Parse ¶
func (pp *PathnamePattern) Parse(pathname string) (params httprouter.Params, err error)
func (*PathnamePattern) String ¶
func (pp *PathnamePattern) String() string
func (*PathnamePattern) Stringify ¶
func (pp *PathnamePattern) Stringify(params httprouter.Params) string
type PlainText ¶
type PlainText struct{}
func (*PlainText) DecodeFrom ¶
type Protobuf ¶ added in v1.0.0
type Protobuf struct{}
func (*Protobuf) DecodeFrom ¶ added in v1.0.0
func (Protobuf) NamedByTag ¶ added in v1.0.0
func (*Protobuf) NewValidator ¶ added in v1.0.0
NewValidator returns empty validator to implements interface `MayValidate` to skip protobuf struct validation
type ReqParam ¶
type ReqParam struct { Param Option Option Tsf Transformer Validator validator.Validator }
type StringBuilders ¶
type StringBuilders struct {
// contains filtered or unexported fields
}
func NewStringBuilders ¶
func NewStringBuilders() *StringBuilders
func (*StringBuilders) NextWriter ¶
func (v *StringBuilders) NextWriter() io.Writer
func (*StringBuilders) SetN ¶
func (v *StringBuilders) SetN(n int)
func (*StringBuilders) StringSlice ¶
func (v *StringBuilders) StringSlice() []string
type StringReader ¶
type StringReader struct {
// contains filtered or unexported fields
}
func NewStringReader ¶
func NewStringReader(v string) *StringReader
func (*StringReader) Interface ¶
func (r *StringReader) Interface() interface{}
func (*StringReader) String ¶
func (r *StringReader) String() string
type StringReaders ¶
type StringReaders struct {
// contains filtered or unexported fields
}
func NewFileHeaderReaders ¶
func NewFileHeaderReaders(headers []*multipart.FileHeader) *StringReaders
func NewStringReaders ¶
func NewStringReaders(values []string) *StringReaders
func (*StringReaders) Interface ¶
func (v *StringReaders) Interface() interface{}
func (*StringReaders) Len ¶
func (v *StringReaders) Len() int
func (*StringReaders) NextReader ¶
func (v *StringReaders) NextReader() io.Reader
type Super ¶
type Super struct { CommonOption // contains filtered or unexported fields }
func NewSuper ¶
func NewSuper(tsfm Transformer, opt *CommonOption) *Super
func (*Super) DecodeFrom ¶
type Transformer ¶
type Transformer interface { Names() []string New(context.Context, typesx.Type) (Transformer, error) EncodeTo(context.Context, io.Writer, any) error DecodeFrom(context.Context, io.Reader, any, ...textproto.MIMEHeader) error }
func NewTransformer ¶
type TsfmAndOption ¶
type TsfmAndOption struct { Transformer Option Option }
type URLEncoded ¶
type URLEncoded struct{ *FlattenParams }
URLEncoded for application/x-www-form-urlencoded
var s = struct { Username string `name:"username"` Nickname string `name:"username,omitempty"` Tags []string `name:"tag"` }{ Username: "name", Tags: []string{"1","2"}, }
will transform to
username=name&tag=1&tag=2
func (*URLEncoded) DecodeFrom ¶
func (t *URLEncoded) DecodeFrom(ctx context.Context, r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (URLEncoded) NamedByTag ¶
func (URLEncoded) NamedByTag() string
func (URLEncoded) Names ¶
func (URLEncoded) Names() []string
func (URLEncoded) New ¶
func (URLEncoded) New(ctx context.Context, typ typesx.Type) (Transformer, error)
func (URLEncoded) String ¶
func (t URLEncoded) String() string
type WithNamedByTag ¶
type WithNamedByTag interface {
NamedByTag() string
}
Click to show internal directories.
Click to hide internal directories.