ehttp

package
v1.1.19 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 25 Imported by: 10

Documentation

Index

Constants

View Source
const PackageName = "client.ehttp"

PackageName 设置包名

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	*resty.Client
	// contains filtered or unexported fields
}

Component 组件

type Config

type Config struct {
	Addr                       string        // 连接地址
	Debug                      bool          // 是否开启调试,默认不开启,开启后并加上export EGO_DEBUG=true,可以看到每次请求,配置名、地址、耗时、请求数据、响应数据
	RawDebug                   bool          // 是否开启原生调试,默认不开启
	ReadTimeout                time.Duration // 读超时,默认2s
	SlowLogThreshold           time.Duration // 慢日志记录的阈值,默认500ms
	IdleConnTimeout            time.Duration // 设置空闲连接时间,默认90 * time.Second
	MaxIdleConns               int           // 设置最大空闲连接数
	MaxIdleConnsPerHost        int           // 设置长连接个数
	EnableTraceInterceptor     bool          // 是否开启链路追踪,默认开启
	EnableKeepAlives           bool          // 是否开启长连接,默认打开
	EnableAccessInterceptor    bool          // 是否开启记录请求数据,默认不开启
	EnableAccessInterceptorRes bool          // 是否开启记录响应参数,默认不开启
	PathRelabel                []Relabel     // path 重命名 (metric 用)

	EnableMetricInterceptor bool // 是否开启Metric采集,默认禁用,开启metrics采集,可能造成metrics在prometheus中膨胀会导致占用大量的prometheus内存
	// contains filtered or unexported fields
}

Config HTTP配置选项

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

type Container

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

Container defines a component instance.

func DefaultContainer

func DefaultContainer() *Container

DefaultContainer returns an default container.

func Load

func Load(key string) *Container

Load 记载配置key

func (*Container) Build

func (c *Container) Build(options ...Option) *Component

Build constructs a specific component from container.

type Option

type Option func(c *Container)

Option 选项

func WithAddr added in v0.3.4

func WithAddr(addr string) Option

WithAddr 设置HTTP地址

func WithDebug added in v0.3.4

func WithDebug(debug bool) Option

WithDebug 设置Debug信息

func WithEnableAccessInterceptor added in v0.3.4

func WithEnableAccessInterceptor(enableAccessInterceptor bool) Option

WithEnableAccessInterceptor 设置开启请求日志

func WithEnableAccessInterceptorRes added in v0.3.11

func WithEnableAccessInterceptorRes(enableAccessInterceptorRes bool) Option

WithEnableAccessInterceptorRes 设置开启请求日志响应参数

func WithEnableKeepAlives added in v0.3.12

func WithEnableKeepAlives(enableKeepAlives bool) Option

WithEnableKeepAlives 设置是否开启长连接,默认打开

func WithEnableMetricInterceptor added in v1.1.17

func WithEnableMetricInterceptor(enableMetricsInterceptor bool) Option

WithEnableMetricInterceptor 设置开启 Metrics 拦截器

func WithEnableTraceInterceptor added in v0.9.2

func WithEnableTraceInterceptor(enableTraceInterceptor bool) Option

WithEnableTraceInterceptor 设置开启Trace拦截器

func WithHTTPClient added in v1.1.17

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient 设置自定义client

func WithIdleConnTimeout added in v0.9.2

func WithIdleConnTimeout(idleConnTimeout time.Duration) Option

WithIdleConnTimeout 设置空闲连接时间

func WithJar added in v1.1.16

func WithJar(jar http.CookieJar) Option

WithJar 设置Cookie,设置后,请求第一次接口后获取Cookie,第二次请求会带上Cookie,适合一些登录场景 例子:cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})

func WithMaxIdleConns added in v0.3.12

func WithMaxIdleConns(maxIdleConns int) Option

WithMaxIdleConns 设置最大空闲连接数

func WithMaxIdleConnsPerHost added in v0.3.12

func WithMaxIdleConnsPerHost(maxIdleConnsPerHost int) Option

WithMaxIdleConnsPerHost 设置长连接个数

func WithPathRelabel added in v1.1.10

func WithPathRelabel(match string, replacement string) Option

WithPathRelabel 设置路径重命名

func WithRawDebug added in v0.3.4

func WithRawDebug(rawDebug bool) Option

WithRawDebug 设置原始Debug信息

func WithReadTimeout added in v0.3.4

func WithReadTimeout(readTimeout time.Duration) Option

WithReadTimeout 设置读超时

func WithSlowLogThreshold added in v0.3.4

func WithSlowLogThreshold(slowLogThreshold time.Duration) Option

WithSlowLogThreshold 设置慢日志阈值

type Relabel added in v1.1.10

type Relabel struct {
	Match string

	Replacement string
	// contains filtered or unexported fields
}

Relabel ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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