client

package
v0.0.0-...-7429660 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGet     = "GET"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodDelete  = "DELETE"
	MethodPatch   = "PATCH"
	MethodHead    = "HEAD"
	MethodOptions = "OPTIONS"
)
View Source
const (
	Success            = 0
	ChannelBroken      = 9
	FailedPrecondition = 100
	Unavailable        = 101
	Canceled           = 102
	DeadlineExceeded   = 103
	ConfigLb           = 104
	BreakerOpen        = 105
	LimitedExceeded    = 106
	UnKnown            = 1001
)

Variables

This section is empty.

Functions

func RegisterOnGlobalStage

func RegisterOnGlobalStage(plugFunc ...HandlerFunc)

plugins will be effect always

func RegisterOnRequestStage

func RegisterOnRequestStage(plugFunc ...HandlerFunc)

plugins will be effect for a http request or a http route

Types

type Body

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

func (*Body) Close

func (b *Body) Close() error

func (*Body) Read

func (b *Body) Read(data []byte) (int, error)

type Client

type Client interface {
	Call(*Request) (*Response, error)
	Use(p ...HandlerFunc)
}

client interface

var DefaultClient Client

Deprecated: DefaultClient should not use anymore.

func NewClient

func NewClient(opts ...Option) Client

type Context

type Context struct {
	Ctx  context.Context
	Req  *Request
	Resp *Response
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortErr

func (c *Context) AbortErr(err error)

func (*Context) Err

func (c *Context) Err() error

func (*Context) Next

func (c *Context) Next()

type Func

type Func func(*Request) (*Response, error)

func (Func) Call

func (f Func) Call(req *Request) (*Response, error)

func (Func) Use

func (f Func) Use(p ...HandlerFunc)

type HandlerFunc

type HandlerFunc func(c *Context)

core plugin encapsulation

func (HandlerFunc) Do

func (p HandlerFunc) Do(ctx context.Context, flow core.Core)

type Option

type Option func(*Options)

func Breaker

func Breaker(config *breaker.Config) Option

func Cluster

func Cluster(clu *upstream.Cluster) Option

func DialTimeout

func DialTimeout(d time.Duration) Option

func IdleConnTimeout

func IdleConnTimeout(d time.Duration) Option

func KeepAliveTimeout

func KeepAliveTimeout(d time.Duration) Option

func KeepAlivesDisable

func KeepAlivesDisable(t bool) Option

if true, do not re-use of TCP connections

func Limiter

func Limiter(config *ratelimit.Config) Option

func LocalName

func LocalName(n string) Option

func Logger

func Logger(logger log.Kit) Option

func MaxIdleConns

func MaxIdleConns(d int) Option

func MaxIdleConnsPerHost

func MaxIdleConnsPerHost(d int) Option

func Namespace

func Namespace(n string) Option

func ProtoType

func ProtoType(p string) Option

func RequestTimeout

func RequestTimeout(d time.Duration) Option

func RetryTimes

func RetryTimes(d int) Option

func ServiceName

func ServiceName(sn string) Option

func SlowTimeout

func SlowTimeout(d time.Duration) Option

func Tracer

func Tracer(tracer opentracing.Tracer) Option

func WithClient

func WithClient(client *http.Client) Option

type Options

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

type Request

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

func NewRequest

func NewRequest(ctx ...context.Context) *Request

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

func (*Request) AddQueryParam

func (r *Request) AddQueryParam(key, value string) *Request

func (*Request) AddQueryParamInt

func (r *Request) AddQueryParamInt(key string, value int) *Request

func (*Request) AddQueryParamInt64

func (r *Request) AddQueryParamInt64(key string, value int64) *Request

func (*Request) AddQueryParamUint64

func (r *Request) AddQueryParamUint64(key string, value uint64) *Request

func (*Request) Baggage

func (r *Request) Baggage(key string) string

获取当前请求中已有的baggage信息

func (*Request) DelHeader

func (r *Request) DelHeader(key string) *Request

func (*Request) ForeachBaggage

func (r *Request) ForeachBaggage(handler func(key, val string) error) error

遍历所有已设置的用户自定义baggage信息

func (*Request) RawRequest

func (r *Request) RawRequest() *http.Request

RawRequest() build a http request, after RawRequest(), Request should not be changed by WithXXX func

func (*Request) SetBaggage

func (r *Request) SetBaggage(key, value string)

设置用户自定义信息,用于透传到下游各个节点

func (*Request) WithBigBody

func (r *Request) WithBigBody(body io.Reader) *Request

func (*Request) WithBody

func (r *Request) WithBody(body io.Reader) *Request

func (*Request) WithCookie

func (r *Request) WithCookie(ck *http.Cookie) *Request

func (*Request) WithFormData

func (r *Request) WithFormData(data map[string]string) *Request

`application/x-www-form-urlencoded`

func (*Request) WithMethod

func (r *Request) WithMethod(method string) *Request

func (*Request) WithMultiCookie

func (r *Request) WithMultiCookie(cks []*http.Cookie) *Request

func (*Request) WithMultiHeader

func (r *Request) WithMultiHeader(headers map[string]string) *Request

func (*Request) WithMultiQueryParam

func (r *Request) WithMultiQueryParam(params map[string]string) *Request

func (*Request) WithOption

func (r *Request) WithOption(ro *RequestOption) *Request

func (*Request) WithPath

func (r *Request) WithPath(path string) *Request

func (*Request) WithPathParams

func (r *Request) WithPathParams(params map[string]string) *Request

url params: /v1/users/:userId/:subAccountId/details

func (*Request) WithQueryParam

func (r *Request) WithQueryParam(key, value string) *Request

func (*Request) WithQueryParamInt

func (r *Request) WithQueryParamInt(key string, value int) *Request

func (*Request) WithQueryParamInt64

func (r *Request) WithQueryParamInt64(key string, value int64) *Request

func (*Request) WithQueryParamUint64

func (r *Request) WithQueryParamUint64(key string, value uint64) *Request

func (*Request) WithRequest

func (r *Request) WithRequest(req *http.Request) *Request

func (*Request) WithScheme deprecated

func (r *Request) WithScheme(scheme string) *Request

Deprecated: WithScheme func should not use anymore. should config proto type on config: proto="http" or proto="https"

func (*Request) WithStruct

func (r *Request) WithStruct(s interface{}) *Request

func (*Request) WithURL

func (r *Request) WithURL(uri string) *Request

WithURL() set url.URL{}, after setting, will use this url.URL{} value first and only. attention: param uri should not abs url, if uri is abs url, it's scheme and host will be not effect.

type RequestOption

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

func (*RequestOption) MetricTags

func (ro *RequestOption) MetricTags(t map[string]string) *RequestOption

func (*RequestOption) RequestTimeoutMS

func (ro *RequestOption) RequestTimeoutMS(timeout int) *RequestOption

func (*RequestOption) RetryTimes

func (ro *RequestOption) RetryTimes(cnt int) *RequestOption

func (*RequestOption) SlowTimeoutMS

func (ro *RequestOption) SlowTimeoutMS(timeout int) *RequestOption

type Response

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

func BuildResp

func BuildResp(req *http.Request, resp *http.Response) (*Response, error)

Response should be close by caller

func (*Response) Body

func (r *Response) Body() *Body

func (*Response) Bytes

func (r *Response) Bytes() []byte

func (*Response) Code

func (r *Response) Code() int

func (*Response) Error

func (r *Response) Error() error

func (*Response) GetHeader

func (r *Response) GetHeader(key string) string

func (*Response) JSON

func (r *Response) JSON(obj interface{}) error

func (*Response) RawRequest

func (r *Response) RawRequest() *http.Request

func (*Response) RawResponse

func (r *Response) RawResponse() *http.Response

func (*Response) Save

func (r *Response) Save(fileName string) error

func (*Response) String

func (r *Response) String() string

Jump to

Keyboard shortcuts

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