httplib

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 22 Imported by: 1

README

clients

Documentation

Index

Constants

View Source
const (
	HeaderKeyDowngrade          = "X-Downgrade-Status" // 降级key
	HeaderValueDowngradeStatic  = "STATIC"
	HeaderValueDowngradeDynamic = "DYNAMIC"
	HeaderKeyCircuitbreaking    = "X-Envoy-Circuitbreaking" // 熔断
)

Variables

This section is empty.

Functions

func Close

func Close()

func SetDefaultHttpClient

func SetDefaultHttpClient(client *HttpClient)

Types

type DataFlow

type DataFlow struct {
	Err error
	// contains filtered or unexported fields
}

DataFlow 是核心数据结构,用来保存http请求的中间状态数据,并负责发送请求和解析回复。

func Delete

func Delete(url string) *DataFlow

Delete 调用默认http客户端的DELETE方法

func Get

func Get(url string) *DataFlow

Get 调用默认http客户端的GET方法

func Patch

func Patch(url string) *DataFlow

Patch 调用默认http客户端的PATCH方法

func Post

func Post(url string) *DataFlow

Post 调用默认http客户端的POST方法

func Put

func Put(url string) *DataFlow

Put 调用默认http客户端的PUT方法

func (*DataFlow) AddHeader

func (df *DataFlow) AddHeader(h H) *DataFlow

AddHeader 设置请求的http header,传入map结构

func (*DataFlow) AddHeaderKV

func (df *DataFlow) AddHeaderKV(key string, values ...string) *DataFlow

AddHeaderKV 设置请求的http header

func (*DataFlow) AddQuery

func (df *DataFlow) AddQuery(key, value string) *DataFlow

AddQuery 增加一个url query键值对

func (*DataFlow) AddWWWForm

func (df *DataFlow) AddWWWForm(key string, values ...string) *DataFlow

AddWWWForm 提供简便的x-www-form-urlencoded格式调用接口

func (*DataFlow) BindBytes

func (df *DataFlow) BindBytes(b *[]byte) *DataFlow

BindBytes 将bytes值与body绑定

func (*DataFlow) BindFloat

func (df *DataFlow) BindFloat(f *float64) *DataFlow

BindFloat 将float值与body绑定

func (*DataFlow) BindHeader

func (df *DataFlow) BindHeader(header H) *DataFlow

func (*DataFlow) BindInt

func (df *DataFlow) BindInt(i *int) *DataFlow

BindInt 将int值与body绑定

func (*DataFlow) BindJson

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

BindJson 将json结构对象与body绑定 注意obj必须是一个指针

func (*DataFlow) BindString

func (df *DataFlow) BindString(s *string) *DataFlow

BindString 将string值与body绑定

func (*DataFlow) CircuitBreaker

func (df *DataFlow) CircuitBreaker(resource string, f func() error) *DataFlow

func (*DataFlow) Degrade

func (df *DataFlow) Degrade(f func() error) *DataFlow

Degrade 注册降级回调函数

func (*DataFlow) Do

func (df *DataFlow) Do(ctx context.Context) (statusCode int, err error)

func (*DataFlow) SetBody

func (df *DataFlow) SetBody(b []byte) *DataFlow

SetBody 直接设置http body

func (*DataFlow) SetContentType

func (df *DataFlow) SetContentType(t string) *DataFlow

SetContentType 设置http header的ContentType

func (*DataFlow) SetFormWithMap

func (df *DataFlow) SetFormWithMap(data map[string]interface{}) *DataFlow

func (*DataFlow) SetJson

func (df *DataFlow) SetJson(body interface{}) *DataFlow

SetJson 设置请求体,格式是json

func (*DataFlow) SetQuery

func (df *DataFlow) SetQuery(q Query) *DataFlow

SetQuery 设置url query字段

func (*DataFlow) SetWWWForm

func (df *DataFlow) SetWWWForm(f WWWForm) *DataFlow

SetWWWForm 设置请求体,格式是x-www-form-urlencoded

func (*DataFlow) Timeout

func (df *DataFlow) Timeout(t time.Duration) *DataFlow

Timeout 设置请求的超时时间

func (*DataFlow) WrapDoFunc

func (df *DataFlow) WrapDoFunc(f func(DoFunc) DoFunc)

type DoFunc

type DoFunc func(*DataFlow, context.Context) (int, error)

type Duration

type Duration struct {
	time.Duration
}

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type FastHeaderCarrier

type FastHeaderCarrier struct {
	*fasthttp.Request
	// contains filtered or unexported fields
}

func NewFastHeaderCarrier

func NewFastHeaderCarrier(req *fasthttp.Request) *FastHeaderCarrier

func (FastHeaderCarrier) Get

func (fhc FastHeaderCarrier) Get(key string) string

func (FastHeaderCarrier) Keys

func (fhc FastHeaderCarrier) Keys() []string

func (FastHeaderCarrier) Set

func (fhc FastHeaderCarrier) Set(key string, value string)

type H

http header类型

type HttpClient

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

func Default

func Default() *HttpClient

func DefaultHttpClient

func DefaultHttpClient() *HttpClient

func New

func New(opt *Option, logger xlog.Logger, metrics metrics.Provider, tracer tracer.Provider) (*HttpClient, error)

func (*HttpClient) Close

func (c *HttpClient) Close()

func (*HttpClient) Delete

func (c *HttpClient) Delete(url string) *DataFlow

Delete 调用http客户端的DELETE方法

func (*HttpClient) Get

func (c *HttpClient) Get(url string) *DataFlow

Get 调用http客户端的GET方法

func (*HttpClient) Patch

func (c *HttpClient) Patch(url string) *DataFlow

Patch 调用http客户端的PATCH方法

func (*HttpClient) Post

func (c *HttpClient) Post(url string) *DataFlow

Post 调用http客户端的POST方法

func (*HttpClient) Put

func (c *HttpClient) Put(url string) *DataFlow

Put 调用http客户端的PUT方法

type Option

type Option struct {
	// User-Agent header,如果为空会设置默认header
	Name string

	// 如果为true,即使Name为空也不设置默认User-Agent
	NoDefaultUserAgentHeader bool

	// TLS配置,需要拆分
	TLSConfig *tls.Config

	// 每个host的最大连接数
	MaxConnsPerHost int

	// 空闲的keep-alive连接最大关闭时间
	MaxIdleConnDuration time.Duration

	// keep-alive连接最大关闭时间
	MaxConnDuration time.Duration

	// 最大重试次数
	MaxIdemponentCallAttempts int

	// 每个连接的读缓存大小,会限制最大header长度
	ReadBufferSize int

	// 每个连接的写缓存大小
	WriteBufferSize int

	// 最大的回复读取时间
	ReadTimeout time.Duration

	// 最大的写请求事件
	WriteTimeout time.Duration

	// 最大的回复body大小
	MaxResponseBodySize int

	// 等待空闲连接的最大时间。默认情况不等待,如果没有空闲连接返回ErrNoFreeConns错误。
	MaxConnWaitTimeout time.Duration
	//
	EnableTracer bool
}

func DefaultOption

func DefaultOption() *Option

type Query

type Query = url.Values

url query结构

type WWWForm

type WWWForm = url.Values

x-www-form-urlencoded body类型

Jump to

Keyboard shortcuts

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