Documentation ¶
Index ¶
- Variables
- func ContextWithTransformerMgr(ctx context.Context, mgr TransformerMgr) context.Context
- func IsBytes(tpe typesutil.Type) bool
- func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader
- func MustNewFileHeader(fieldName string, filename string, r io.Reader) *multipart.FileHeader
- func NamedStructFieldValueRange(rv reflect.Value, ...)
- func NewFileHeader(fieldName string, filename string, r io.Reader) (*multipart.FileHeader, error)
- func NewValidator(ctx context.Context, field typesutil.StructField, validateStr string, ...) (validator.Validator, error)
- func PtrTo(typ typesutil.Type) typesutil.Type
- func TagValueAndFlagsByTagString(tagString string) (string, map[string]bool)
- type Adder
- type CommonTransformOption
- type FlattenParams
- type FormTransformer
- func (transformer *FormTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
- func (transformer *FormTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
- func (FormTransformer) NamedByTag() string
- func (FormTransformer) Names() []string
- func (FormTransformer) New(ctx context.Context, typ typesutil.Type) (Transformer, error)
- func (transformer *FormTransformer) String() string
- type JSONTransformer
- func (JSONTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
- func (transformer *JSONTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
- func (JSONTransformer) NamedByTag() string
- func (JSONTransformer) Names() []string
- func (JSONTransformer) New(context.Context, typesutil.Type) (Transformer, error)
- func (transformer *JSONTransformer) String() string
- type MayValidator
- type MaybeTransformer
- type MultipartTransformer
- func (transformer *MultipartTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
- func (transformer *MultipartTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
- func (MultipartTransformer) NamedByTag() string
- func (MultipartTransformer) Names() []string
- func (MultipartTransformer) New(ctx context.Context, typ typesutil.Type) (Transformer, error)
- func (transformer *MultipartTransformer) String() string
- type PathWalker
- type PlainTextTransformer
- func (PlainTextTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
- func (t *PlainTextTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
- func (PlainTextTransformer) NamedByTag() string
- func (PlainTextTransformer) Names() []string
- func (PlainTextTransformer) New(context.Context, typesutil.Type) (Transformer, error)
- func (t *PlainTextTransformer) String() string
- type Transformer
- type TransformerFactory
- type TransformerMgr
- type TransformerOption
- type XMLTransformer
- func (XMLTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
- func (t *XMLTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
- func (XMLTransformer) NamedByTag() string
- func (XMLTransformer) Names() []string
- func (XMLTransformer) New(context.Context, typesutil.Type) (Transformer, error)
- func (t *XMLTransformer) String() string
Constants ¶
This section is empty.
Variables ¶
View Source
var TagMIMEKey = "mime"
View Source
var TagNameKey = "name"
View Source
var TransformerMgrDefault = &TransformerFactory{}
Functions ¶
func ContextWithTransformerMgr ¶ added in v1.5.0
func ContextWithTransformerMgr(ctx context.Context, mgr TransformerMgr) context.Context
func MIMEHeader ¶
func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader
func MustNewFileHeader ¶
func NewFileHeader ¶
func NewValidator ¶
func NewValidator(ctx context.Context, field typesutil.StructField, validateStr string, omitempty bool, transformer Transformer) (validator.Validator, error)
Types ¶
type CommonTransformOption ¶
type FlattenParams ¶
type FlattenParams struct {
// contains filtered or unexported fields
}
func (*FlattenParams) CollectParams ¶
func (*FlattenParams) NewValidator ¶
func (FlattenParams) String ¶
func (FlattenParams) String() string
func (*FlattenParams) Validate ¶
func (params *FlattenParams) Validate(v interface{}) error
type FormTransformer ¶
type FormTransformer struct {
*FlattenParams
}
func (*FormTransformer) DecodeFromReader ¶
func (transformer *FormTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (*FormTransformer) EncodeToWriter ¶
func (transformer *FormTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
func (FormTransformer) NamedByTag ¶
func (FormTransformer) NamedByTag() string
func (FormTransformer) Names ¶
func (FormTransformer) Names() []string
transformer 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 be transform to
username=name&tag=1&tag=2
func (FormTransformer) New ¶
func (FormTransformer) New(ctx context.Context, typ typesutil.Type) (Transformer, error)
func (*FormTransformer) String ¶
func (transformer *FormTransformer) String() string
type JSONTransformer ¶
type JSONTransformer struct { }
func (JSONTransformer) DecodeFromReader ¶
func (JSONTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (*JSONTransformer) EncodeToWriter ¶
func (transformer *JSONTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
func (JSONTransformer) NamedByTag ¶
func (JSONTransformer) NamedByTag() string
func (JSONTransformer) Names ¶
func (JSONTransformer) Names() []string
func (JSONTransformer) New ¶
func (JSONTransformer) New(context.Context, typesutil.Type) (Transformer, error)
func (*JSONTransformer) String ¶
func (transformer *JSONTransformer) String() string
type MayValidator ¶ added in v1.5.0
type MaybeTransformer ¶
type MaybeTransformer struct {
// contains filtered or unexported fields
}
func NewMaybeTransformer ¶
func NewMaybeTransformer(transformer Transformer, opt *CommonTransformOption) *MaybeTransformer
func (*MaybeTransformer) Add ¶
func (t *MaybeTransformer) Add(key string, v interface{}, adder Adder) error
func (*MaybeTransformer) DecodeFromReader ¶
func (t *MaybeTransformer) DecodeFromReader(r io.Reader, v interface{}) error
func (*MaybeTransformer) EncodeToWriter ¶
func (t *MaybeTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
type MultipartTransformer ¶
type MultipartTransformer struct {
*FlattenParams
}
func (*MultipartTransformer) DecodeFromReader ¶
func (transformer *MultipartTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (*MultipartTransformer) EncodeToWriter ¶
func (transformer *MultipartTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
func (MultipartTransformer) NamedByTag ¶
func (MultipartTransformer) NamedByTag() string
func (MultipartTransformer) Names ¶
func (MultipartTransformer) Names() []string
transformer for multipart/form-data
func (MultipartTransformer) New ¶
func (MultipartTransformer) New(ctx context.Context, typ typesutil.Type) (Transformer, error)
func (*MultipartTransformer) String ¶
func (transformer *MultipartTransformer) String() string
type PathWalker ¶
type PathWalker struct {
// contains filtered or unexported fields
}
func (*PathWalker) Enter ¶
func (pw *PathWalker) Enter(i interface{})
func (*PathWalker) Exit ¶
func (pw *PathWalker) Exit()
func (*PathWalker) Paths ¶
func (pw *PathWalker) Paths() []interface{}
func (*PathWalker) String ¶
func (pw *PathWalker) String() string
type PlainTextTransformer ¶
type PlainTextTransformer struct { }
func (PlainTextTransformer) DecodeFromReader ¶
func (PlainTextTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (*PlainTextTransformer) EncodeToWriter ¶
func (t *PlainTextTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
func (PlainTextTransformer) NamedByTag ¶
func (PlainTextTransformer) NamedByTag() string
func (PlainTextTransformer) Names ¶
func (PlainTextTransformer) Names() []string
func (PlainTextTransformer) New ¶
func (PlainTextTransformer) New(context.Context, typesutil.Type) (Transformer, error)
func (*PlainTextTransformer) String ¶
func (t *PlainTextTransformer) String() string
type Transformer ¶
type Transformer interface { // name or alias of transformer // prefer using some keyword about content-type Names() []string // create transformer new transformer instance by type // in this step will to check transformer is valid for type New(context.Context, typesutil.Type) (Transformer, error) // named by tag NamedByTag() string // encode to writer EncodeToWriter(w io.Writer, v interface{}) (mediaType string, err error) // decode from reader DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error // Content-Type String() string }
type TransformerFactory ¶
type TransformerFactory struct {
// contains filtered or unexported fields
}
func (*TransformerFactory) NewTransformer ¶
func (c *TransformerFactory) NewTransformer(ctx context.Context, typ typesutil.Type, opt TransformerOption) (Transformer, error)
func (*TransformerFactory) Register ¶
func (c *TransformerFactory) Register(transformers ...Transformer)
type TransformerMgr ¶
type TransformerMgr interface {
NewTransformer(context.Context, typesutil.Type, TransformerOption) (Transformer, error)
}
func TransformerMgrFromContext ¶ added in v1.5.0
func TransformerMgrFromContext(ctx context.Context) TransformerMgr
type TransformerOption ¶
type TransformerOption struct { FieldName string MIME string CommonTransformOption }
func TransformerOptionFromStructField ¶
func TransformerOptionFromStructField(field typesutil.StructField) TransformerOption
func (TransformerOption) String ¶
func (op TransformerOption) String() string
type XMLTransformer ¶
type XMLTransformer struct { }
func (XMLTransformer) DecodeFromReader ¶
func (XMLTransformer) DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error
func (*XMLTransformer) EncodeToWriter ¶
func (t *XMLTransformer) EncodeToWriter(w io.Writer, v interface{}) (string, error)
func (XMLTransformer) NamedByTag ¶
func (XMLTransformer) NamedByTag() string
func (XMLTransformer) Names ¶
func (XMLTransformer) Names() []string
func (XMLTransformer) New ¶
func (XMLTransformer) New(context.Context, typesutil.Type) (Transformer, error)
func (*XMLTransformer) String ¶
func (t *XMLTransformer) String() string
Click to show internal directories.
Click to hide internal directories.