dataflow

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 18 Imported by: 46

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,
		},
	}
)

Functions

func Register

func Register(name string, filter NewFilter)

func ToBodyType

func ToBodyType(s string) color.BodyType

ToBodyType Returns the http body type, which mainly affects color highlighting

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

	*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

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

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

func (df *DataFlow) Export() *export

Export 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) HEAD

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

HEAD send HTTP HEAD method

func (*DataFlow) IsDebug

func (df *DataFlow) IsDebug() bool

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

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

SetBody set the data to the http body

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

func (*DataFlow) SetGout

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

func (*DataFlow) SetHeader

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

SetHeader send http header

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

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

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

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

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 DebugFunc

type DebugFunc func(*DebugOption)

DebugFunc DebugOpt is a function that manipulates core data structures

func (DebugFunc) Apply

func (f DebugFunc) Apply(o *DebugOption)

Apply is an interface for operating DebugOption

type DebugOpt

type DebugOpt interface {
	Apply(*DebugOption)
}

DebugOpt is an interface for operating DebugOption

func NoColor

func NoColor() DebugOpt

NoColor Turn off color highlight debug mode

type DebugOption

type DebugOption struct {
	Write       io.Writer
	Debug       bool
	Color       bool
	ReqBodyType string
	RspBodyType string
}

DebugOption Debug mode core data structure

type Export

type Export interface {
	Curl()
}

type Filter

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

type Gout

type Gout struct {
	*http.Client
	DataFlow // TODO 优化
	// contains filtered or unexported fields
}

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
	// 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

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

func (r *Req) SetRequest(req *http.Request)

type Retry

type Retry interface {
	Attempt(attempt int) Retry
	WaitTime(waitTime time.Duration) Retry
	MaxWaitTime(maxWaitTime time.Duration) Retry
	Do() error
}

Jump to

Keyboard shortcuts

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