transformers

package
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 24 Imported by: 2

Documentation

Index

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 IsBytes

func IsBytes(tpe typesutil.Type) bool

func MIMEHeader

func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader

func MustNewFileHeader

func MustNewFileHeader(fieldName string, filename string, r io.Reader) *multipart.FileHeader

func NamedStructFieldValueRange

func NamedStructFieldValueRange(rv reflect.Value, fn func(fieldValue reflect.Value, field *reflect.StructField), tags ...string)

func NewFileHeader

func NewFileHeader(fieldName string, filename string, r io.Reader) (*multipart.FileHeader, error)

func NewValidator

func NewValidator(ctx context.Context, field typesutil.StructField, validateStr string, omitempty bool, transformer Transformer) (validator.Validator, error)

func PtrTo

func PtrTo(typ typesutil.Type) typesutil.Type

func TagValueAndFlagsByTagString

func TagValueAndFlagsByTagString(tagString string) (string, map[string]bool)

Types

type Adder

type Adder interface {
	Add(key string, value string)
}

type CommonTransformOption

type CommonTransformOption struct {
	// when enable
	// should ignore value when value is empty
	Omitempty bool
	Explode   bool
}

type FlattenParams

type FlattenParams struct {
	// contains filtered or unexported fields
}

func (*FlattenParams) CollectParams

func (params *FlattenParams) CollectParams(ctx context.Context, typ typesutil.Type) error

func (*FlattenParams) NewValidator

func (params *FlattenParams) NewValidator(ctx context.Context, typ typesutil.Type) (validator.Validator, error)

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) 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) String

func (transformer *JSONTransformer) String() string

type MayValidator added in v1.5.0

type MayValidator interface {
	NewValidator(ctx context.Context, typ typesutil.Type) (validator.Validator, error)
}

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) 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) 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) String

func (t *XMLTransformer) String() string

Jump to

Keyboard shortcuts

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