encode

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplMessage = errors.New("The proto.Message interface is not implemented")
View Source
var ErrNotJSON = errors.New("Not json data")
View Source
var ErrNotXML = errors.New("Not xml data")
View Source
var ErrNotYAML = errors.New("Not yaml data")
View Source
var ErrUnsupported = errors.New("Encode:Unsupported type")

ErrUnsupported Unsupported type error returned

Functions

func Encode

func Encode(in interface{}, a Adder) error

Encode core entry function in 的类型可以是 struct map []string

func XMLValid

func XMLValid(b []byte) bool

func YAMLValid

func YAMLValid(b []byte) bool

Types

type Adder

type Adder interface {
	Add(key string, v reflect.Value, sf reflect.StructField) error
	Name() string
}

Adder interface

type BodyEncode

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

BodyEncode body encoder structure

func NewBodyEncode

func NewBodyEncode(obj interface{}) *BodyEncode

NewBodyEncode create a new body encoder

func (*BodyEncode) Encode

func (b *BodyEncode) Encode(w io.Writer) error

Encode Add Encoder core function, used to set io.Writer into the http body

func (*BodyEncode) Name

func (b *BodyEncode) Name() string

Name http body Encoder name

type Encoder

type Encoder interface {
	Encode(w io.Writer) error
	Name() string
}

Encoder is the encoding interface

type FormEncode

type FormEncode struct {
	*multipart.Writer
}

FormEncode form-data encoder structure

func NewFormEncode

func NewFormEncode(b *bytes.Buffer) *FormEncode

NewFormEncode create a new form-data encoder

func (*FormEncode) Add

func (f *FormEncode) Add(key string, v reflect.Value, sf reflect.StructField) (err error)

Add Encoder core function, used to set each key / value into the http form-data

func (*FormEncode) CreateFormFile

func (f *FormEncode) CreateFormFile(fieldName, fileName, contentType string) (io.Writer, error)

CreateFormFile 重写原来net/http里面的CreateFormFile函数

func (*FormEncode) End

func (f *FormEncode) End() error

End refresh data

func (*FormEncode) Name

func (f *FormEncode) Name() string

Name form-data Encoder name

type HeaderEncode

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

HeaderEncode http header encoder structure

func NewHeaderEncode

func NewHeaderEncode(req *http.Request) *HeaderEncode

NewHeaderEncode create a new http header encoder

func (*HeaderEncode) Add

Add Encoder core function, used to set each key / value into the http header

func (*HeaderEncode) Name

func (h *HeaderEncode) Name() string

Name header Encoder name

type JSONEncode

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

JSONEncode json encoder structure

func NewJSONEncode

func NewJSONEncode(obj interface{}) *JSONEncode

NewJSONEncode create a new json encoder

func (*JSONEncode) Encode

func (j *JSONEncode) Encode(w io.Writer) (err error)

Encode json encoder

func (*JSONEncode) Name

func (j *JSONEncode) Name() string

Name json Encoder name

type ProtoBufEncode

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

func NewProtoBufEncode

func NewProtoBufEncode(obj interface{}) *ProtoBufEncode

func (*ProtoBufEncode) Encode

func (p *ProtoBufEncode) Encode(w io.Writer) (err error)

func (*ProtoBufEncode) Name

func (p *ProtoBufEncode) Name() string

type QueryEncode

type QueryEncode struct {
	setting.Setting
	// contains filtered or unexported fields
}

QueryEncode URL query encoder structure

func NewQueryEncode

func NewQueryEncode(req *http.Request, s setting.Setting) *QueryEncode

NewQueryEncode create a new URL query encoder

func (*QueryEncode) Add

Add Encoder core function, used to set each key / value into the http URL query

func (*QueryEncode) End

func (q *QueryEncode) End() string

End URL query structured data into strings

func (*QueryEncode) Name

func (q *QueryEncode) Name() string

Name URL query Encoder name

type WWWFormEncode

type WWWFormEncode struct {
	setting.Setting
	// contains filtered or unexported fields
}

WWWFormEncode x-www-form-urlencoded encoder structure

func NewWWWFormEncode

func NewWWWFormEncode(s setting.Setting) *WWWFormEncode

NewWWWFormEncode create a new x-www-form-urlencoded encoder

func (*WWWFormEncode) Add

Add Encoder core function, used to set each key / value into the http x-www-form-urlencoded 这里value的设置暴露 reflect.Value和 reflect.StructField原因如下 reflect.Value把value转成字符串 reflect.StructField主要是可以在Add函数里面获取tag相关信息

func (*WWWFormEncode) Encode

func (we *WWWFormEncode) Encode(obj interface{}) (err error)

Encode x-www-form-urlencoded encoder

func (*WWWFormEncode) End

func (we *WWWFormEncode) End(w io.Writer) error

func (*WWWFormEncode) Name

func (we *WWWFormEncode) Name() string

Name x-www-form-urlencoded Encoder name

type XMLEncode

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

XMLEncode xml encoder structure

func NewXMLEncode

func NewXMLEncode(obj interface{}) *XMLEncode

NewXMLEncode create a new xml encoder

func (*XMLEncode) Encode

func (x *XMLEncode) Encode(w io.Writer) (err error)

Encode xml encoder

func (*XMLEncode) Name

func (x *XMLEncode) Name() string

Name xml Encoder name

type YAMLEncode

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

YAMLEncode yaml encoder structure

func NewYAMLEncode

func NewYAMLEncode(obj interface{}) *YAMLEncode

NewYAMLEncode create a new yaml encoder

func (*YAMLEncode) Encode

func (y *YAMLEncode) Encode(w io.Writer) (err error)

Encode yaml encoder

func (*YAMLEncode) Name

func (y *YAMLEncode) Name() string

Name yaml Encoder name

Jump to

Keyboard shortcuts

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