httpClient

package
v1.10.9 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpHeaderService = "SERVICE"
	// trace 日志前缀标识(放在[]zap.Field的第一个位置提高效率)
	TopicType = "_tp"
	// 业务日志名字
	LogNameServer = "server"
	// access 日志文件名字
	LogNameAccess = "access"
	// module 日志文件名字
	LogNameModule = "module"

	TraceHeaderKey      = "Uber-Trace-Id"
	LogIDHeaderKey      = "X_BD_LOGID"
	LogIDHeaderKeyLower = "x_bd_logid"
)

Variables

This section is empty.

Functions

func GetFormatRequestTime

func GetFormatRequestTime(time time.Time) string

func GetRequestCost

func GetRequestCost(start, end time.Time) float64

func GetRequestData

func GetRequestData(requestBody interface{}) (encodeData string, err error)

func GetUrlData

func GetUrlData(data map[string]string) (string, error)

func Str2bytes

func Str2bytes(s string) []byte

Types

type ApiConf

type ApiConf struct {
	Service        string        `yaml:"service"`
	AppKey         string        `yaml:"appkey"`
	Domain         string        `yaml:"domain"`
	Timeout        time.Duration `yaml:"timeout"`
	ConnectTimeout time.Duration `yaml:"connectTimeout"`
	Retry          int           `yaml:"retry"`
	HttpStat       bool          `yaml:"httpStat"`
	Proxy          string        `yaml:"proxy"`
	BasicAuth      struct {
		Username string `yaml:"username"`
		Password string `yaml:"password"`
	}
}

func (*ApiConf) GetTransPort

func (entity *ApiConf) GetTransPort() *http.Transport

type ApiRequest

type ApiRequest struct {
	Req *http.Request

	HTTPClient *http.Client
	// 重试策略,可不指定,默认使用`defaultRetryPolicy`(只有在`api.yaml`中指定retry>0 时生效)
	RetryPolicy RetryPolicy
	// 重试间隔机制,可不指定,默认使用`defaultBackOffPolicy`(只有在`api.yaml`中指定retry>0 时生效)
	BackOffPolicy BackOffPolicy
	// contains filtered or unexported fields
}

func (*ApiRequest) GetBackOffPolicy

func (entity *ApiRequest) GetBackOffPolicy() BackOffPolicy

func (*ApiRequest) GetRetryPolicy

func (entity *ApiRequest) GetRetryPolicy() RetryPolicy

type BackOffPolicy

type BackOffPolicy func(attemptCount int) time.Duration

重试策略

type HttpClient

type HttpClient struct {
	layer.Flow
	ApiConf ApiConf
}

func (*HttpClient) MakeRequest

func (entity *HttpClient) MakeRequest(method, url string, data io.Reader, headers map[string]string, cookies map[string]string, bodyType string) (*http.Request, error)

func (*HttpClient) PreUse

func (entity *HttpClient) PreUse(args ...interface{})

func (*HttpClient) Request

func (entity *HttpClient) Request(method string, uri string, reqBody []byte, header map[string]string, cookies map[string]string, contentType string) (data []byte, err error)

type RetryPolicy

type RetryPolicy func(resp *http.Response, err error) bool

retry 策略

Jump to

Keyboard shortcuts

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