dataflow

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultClient The default http client, which has a connection pool
	DefaultClient = http.Client{}
	// DefaultBenchClient is the default http client used by the benchmark,
	// which has a connection pool
	DefaultBenchClient = http.Client{
		Transport: &http.Transport{
			MaxIdleConnsPerHost: 10000,
		},
	}
)
View Source
var GlobalSetting = setting.Setting{
	NotIgnoreEmpty: true,
}

存放全局配置选项

Functions

func Register

func Register(name string, filter NewFilter)

Types

type Bencher

type Bencher interface {
	Concurrent(c int) Bencher
	Number(n int) Bencher
	Rate(rate int) Bencher
	Durations(d time.Duration) Bencher
	Loop(func(c *Context) error) Bencher
	GetReport(r *bench.Report) Bencher
	Do() error
}

type Context

type Context struct {
	Code  int //http code
	Error error

	*DataFlow
}

Context struct

type Curl

type Curl interface {
	LongOption() Curl
	GenAndSend() Curl
	SetOutput(w io.Writer) Curl
	Do() error
}

type DataFlow

type DataFlow struct {
	Req
	// contains filtered or unexported fields
}

DataFlow is the core data structure, including the encoder and decoder of http data

func DELETE

func DELETE(url string) *DataFlow

DELETE send HTTP DELETE method

func GET

func GET(url string) *DataFlow

TODO 这一层可以直接删除 GET send HTTP GET method

func HEAD(url string) *DataFlow

HEAD send HTTP HEAD method

func OPTIONS

func OPTIONS(url string) *DataFlow

OPTIONS send HTTP OPTIONS method

func PATCH

func PATCH(url string) *DataFlow

PATCH send HTTP PATCH method

func POST

func POST(url string) *DataFlow

POST send HTTP POST method

func PUT

func PUT(url string) *DataFlow

PUT send HTTP PUT method

func (*DataFlow) AutoDecodeBody

func (df *DataFlow) AutoDecodeBody() *DataFlow

https://github.com/xishengcai/gout/issues/343 content-encoding会指定response body的压缩方法,支持常用的压缩,gzip, deflate, br等

func (*DataFlow) BindBody

func (df *DataFlow) BindBody(obj interface{}) *DataFlow

BindBody parse the variables in http body to obj. obj must be a pointer variable

func (*DataFlow) BindHeader

func (df *DataFlow) BindHeader(obj interface{}) *DataFlow

BindHeader parse http header to obj variable. obj must be a pointer variable Support string/int/float/slice ... types

func (*DataFlow) BindJSON

func (df *DataFlow) BindJSON(obj interface{}) *DataFlow

BindJSON parse the json string in http body to obj. obj must be a pointer variable

func (*DataFlow) BindXML

func (df *DataFlow) BindXML(obj interface{}) *DataFlow

BindXML parse the xml string in http body to obj. obj must be a pointer variable

func (*DataFlow) BindYAML

func (df *DataFlow) BindYAML(obj interface{}) *DataFlow

BindYAML parse the yaml string in http body to obj. obj must be a pointer variable

func (*DataFlow) Callback

func (df *DataFlow) Callback(cb func(*Context) error) *DataFlow

Callback parse the http body into obj according to the condition (json or string)

func (*DataFlow) Chunked

func (df *DataFlow) Chunked() *DataFlow

Chunked

func (*DataFlow) Code

func (df *DataFlow) Code(httpCode *int) *DataFlow

Code parse the http code into the variable httpCode

func (*DataFlow) DELETE

func (df *DataFlow) DELETE(url string) *DataFlow

DELETE send HTTP DELETE method

func (*DataFlow) Debug

func (df *DataFlow) Debug(d ...interface{}) *DataFlow

Debug start debug mode

func (*DataFlow) Do

func (df *DataFlow) Do() (err error)

Do send function

func (*DataFlow) E

func (df *DataFlow) E() *export

E filter function, use this function to turn on the filter function

func (*DataFlow) Export

func (df *DataFlow) Export() *export

Export filter function, use this function to turn on the filter function

func (*DataFlow) F

func (df *DataFlow) F() *filter

F filter function, use this function to turn on the filter function

func (*DataFlow) Filter

func (df *DataFlow) Filter() *filter

Filter filter function, use this function to turn on the filter function

func (*DataFlow) GET

func (df *DataFlow) GET(url string) *DataFlow

GET send HTTP GET method

func (*DataFlow) GetHost

func (df *DataFlow) GetHost() (string, error)

GetHost return value->host or host:port

func (*DataFlow) HEAD

func (df *DataFlow) HEAD(url string) *DataFlow

HEAD send HTTP HEAD method

func (*DataFlow) IsDebug

func (df *DataFlow) IsDebug() bool

func (*DataFlow) NoAutoContentType

func (df *DataFlow) NoAutoContentType() *DataFlow

https://github.com/xishengcai/gout/issues/264 When calling SetWWWForm(), the Content-Type header will be added automatically, and calling NoAutoContentType() will not add an HTTP header

SetWWWForm "Content-Type", "application/x-www-form-urlencoded" SetJSON "Content-Type", "application/json"

func (*DataFlow) OPTIONS

func (df *DataFlow) OPTIONS(url string) *DataFlow

OPTIONS send HTTP OPTIONS method

func (*DataFlow) PATCH

func (df *DataFlow) PATCH(url string) *DataFlow

PATCH send HTTP PATCH method

func (*DataFlow) POST

func (df *DataFlow) POST(url string) *DataFlow

POST send HTTP POST method

func (*DataFlow) PUT

func (df *DataFlow) PUT(url string) *DataFlow

PUT send HTTP PUT method

func (*DataFlow) RequestUse

func (df *DataFlow) RequestUse(reqModify ...middler.RequestMiddler) *DataFlow

Request middleware

func (*DataFlow) ResponseUse

func (df *DataFlow) ResponseUse(responseModify ...middler.ResponseMiddler) *DataFlow

Response middleware

func (*DataFlow) SetBasicAuth

func (df *DataFlow) SetBasicAuth(username, password string) *DataFlow

SetBasicAuth

func (*DataFlow) SetBody

func (df *DataFlow) SetBody(obj interface{}) *DataFlow

SetBody set the data to the http body, Support string/bytes/io.Reader

func (*DataFlow) SetCookies

func (df *DataFlow) SetCookies(c ...*http.Cookie) *DataFlow

SetCookies set cookies

func (*DataFlow) SetForm

func (df *DataFlow) SetForm(obj ...interface{}) *DataFlow

SetForm send form data to the http body, Support struct/map/array/slice

func (*DataFlow) SetGout

func (df *DataFlow) SetGout(out *Gout)

func (*DataFlow) SetHeader

func (df *DataFlow) SetHeader(obj ...interface{}) *DataFlow

SetHeader send http header, Support struct/map/slice types

func (*DataFlow) SetHost

func (df *DataFlow) SetHost(host string) *DataFlow

SetHost set host

func (*DataFlow) SetJSON

func (df *DataFlow) SetJSON(obj interface{}) *DataFlow

SetJSON send json to the http body, Support raw json(string, []byte)/struct/map types

func (*DataFlow) SetJSONNotEscape

func (df *DataFlow) SetJSONNotEscape(obj interface{}) *DataFlow

SetJSON send json to the http body, Support raw json(string, []byte)/struct/map types 与SetJSON的区一区别就是不转义HTML里面的标签

func (*DataFlow) SetMethod

func (df *DataFlow) SetMethod(method string) *DataFlow

SetMethod set method

func (*DataFlow) SetProtoBuf

func (df *DataFlow) SetProtoBuf(obj interface{}) *DataFlow

SetProtoBuf send yaml to the http body, Support struct types obj必须是结构体指针或者[]byte类型

func (*DataFlow) SetProxy

func (df *DataFlow) SetProxy(proxyURL string) *DataFlow

SetProxy 函数会修改Transport,请像对待全局变量一样对待SetProxy

func (*DataFlow) SetQuery

func (df *DataFlow) SetQuery(obj ...interface{}) *DataFlow

SetQuery send URL query string, Support string/[]byte/struct/map/slice types

func (*DataFlow) SetRequest

func (df *DataFlow) SetRequest(req *http.Request) *DataFlow

func (*DataFlow) SetSOCKS5

func (df *DataFlow) SetSOCKS5(addr string) *DataFlow

SetSOCKS5 函数会修改Transport,请像对待全局变量一样对待SetSOCKS5

func (*DataFlow) SetSetting

func (df *DataFlow) SetSetting(s setting.Setting) *DataFlow

SetSetting

func (*DataFlow) SetTimeout

func (df *DataFlow) SetTimeout(d time.Duration) *DataFlow

SetTimeout set timeout, and WithContext are mutually exclusive functions

func (*DataFlow) SetURL

func (df *DataFlow) SetURL(url string) *DataFlow

SetURL set url

func (*DataFlow) SetWWWForm

func (df *DataFlow) SetWWWForm(obj ...interface{}) *DataFlow

SetWWWForm send x-www-form-urlencoded to the http body, Support struct/map/array/slice types

func (*DataFlow) SetXML

func (df *DataFlow) SetXML(obj interface{}) *DataFlow

SetXML send xml to the http body

func (*DataFlow) SetYAML

func (df *DataFlow) SetYAML(obj interface{}) *DataFlow

SetYAML send yaml to the http body, Support struct,map types

func (*DataFlow) UnixSocket

func (df *DataFlow) UnixSocket(path string) *DataFlow

UnixSocket 函数会修改Transport, 请像对待全局变量一样对待UnixSocket

func (*DataFlow) WithContext

func (df *DataFlow) WithContext(c context.Context) *DataFlow

WithContext set context, and SetTimeout are mutually exclusive functions

type Export

type Export interface {
	Curl()
}

type Filter

type Filter interface {
	Bench() Bencher
	Retry() Retry
}

type Gout

type Gout struct {
	*http.Client
	DataFlow // TODO 优化
}

Gout is the data structure at the beginning of everything

func New

func New(c ...*http.Client) *Gout

New function is mainly used when passing custom http client

type NewFilter

type NewFilter interface {
	New(*DataFlow) interface{}
}

type Req

type Req struct {
	Err error

	// 内嵌字段
	setting.Setting
	// contains filtered or unexported fields
}

Req controls core data structure of http request

func (*Req) Bind

func (r *Req) Bind(req *http.Request, resp *http.Response) (err error)

func (*Req) Client

func (r *Req) Client() *http.Client

func (*Req) Do

func (r *Req) Do() (err error)

Do Send function

func (*Req) GetContext

func (r *Req) GetContext() context.Context

retry模块需要context.Context,所以这里也返回context.Context

func (*Req) Request

func (r *Req) Request() (req *http.Request, err error)

Request Get the http.Request object

func (*Req) Reset

func (r *Req) Reset()

Reset 重置 Req结构体 req 结构布局说明,以decode为例 body 可以支持text, json, yaml, xml,所以定义成接口形式 headerDecode只有一个可能,就定义为具体类型。这里他们的decode实现也不一样 有没有必要,归一化成一种??? TODO:

func (*Req) Response

func (r *Req) Response() (rsp *http.Response, err error)

Response 获取原始http.Response数据结构

type Retry

type Retry interface {
	Attempt(attempt int) Retry
	WaitTime(waitTime time.Duration) Retry
	MaxWaitTime(maxWaitTime time.Duration) Retry
	Func(func(c *Context) error) Retry
	Do() error
}

Jump to

Keyboard shortcuts

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