Documentation ¶
Index ¶
- Constants
- func DefaultUnifyRequestHostHook(url *url.URL) string
- func DefaultUnifyRequestURIHook(url *url.URL) string
- func DynamicDebugLogging(req *resty.Request)
- func NewHTTP(config *Config) *http.Client
- type Client
- type Config
- type Option
- func WithDialTimeout(d time.Duration) Option
- func WithDisabledMetricHostLabel(disabled bool) Option
- func WithEnabledMetric(enabled bool) Option
- func WithEnabledMetricWithURI(enabled bool) Option
- func WithEnabledOtelTrace(enabled bool) Option
- func WithEnabledTrace(enabled bool) Option
- func WithForceAttemptHTTP2(forceAttemptHTTP2 bool) Option
- func WithIdleConnTimeout(d time.Duration) Option
- func WithKeepAlive(d time.Duration) Option
- func WithMaxConnsPerHost(conns int) Option
- func WithMaxIdleConns(conns int) Option
- func WithMaxIdleConnsPerHost(conns int) Option
- func WithTLSClientConfig(tls *tls.Config) Option
- func WithTimeout(d time.Duration) Option
- func WithUnifyRequestHostHook(hook func(url *url.URL) string) Option
- func WithUnifyRequestURIHook(hook func(url *url.URL) string) Option
Constants ¶
View Source
const ( DefaultLabelRequestHost = "-" DefaultLabelRequestURI = "/" )
Variables ¶
This section is empty.
Functions ¶
func DynamicDebugLogging ¶
func DynamicDebugLogging(req *resty.Request)
DynamicDebugLogging open the debug level logging in dynamically
Types ¶
type Client ¶
type Client struct { *resty.Client // contains filtered or unexported fields }
func NewWithConfigOptions ¶
NewWithConfigOptions creates the resty client with Optional config creates resty client with Default config if not pass opts
func (*Client) WithContext ¶
WithContext would retrieve the request with context, so we can attach the tracing transaction into context.
type Config ¶
type Config struct { // DialTimeout controls time maximum timeout of the tcp connect DialTimeout time.Duration // Timeout controls the maximum timeout of the api request which // contains dns lookup, dial, wait for response, etc... Timeout time.Duration // KeepAlive specifies the interval between keep-alive // probes for an active network connection. // If zero, keep-alive probes are sent with a default value // (currently 15 seconds), if supported by the protocol and operating // system. Network protocols or operating systems that do // not support keep-alives ignore this field. // If negative, keep-alive probes are disabled. KeepAlive time.Duration // MaxIdleConns controls the maximum number of idle (keep-alive) // connections across all hosts. Zero means no limit. MaxIdleConns int // MaxIdleConnsPerHost, if non-zero, controls the maximum idle // (keep-alive) connections to keep per-host. If zero, // DefaultMaxIdleConnsPerHost is used. MaxIdleConnsPerHost int // MaxConnsPerHost optionally limits the total number of // connections per host, including connections in the dialing, // active, and idle states. On limit violation, dials will block. // // Zero means no limit. MaxConnsPerHost int // IdleConnTimeout is the maximum amount of time an idle // (keep-alive) connection will remain idle before closing // itself. // Zero means no limit. IdleConnTimeout time.Duration // EnabledMetric if true, would export api client _metrics to the prometheus. // e.g. dns/tls/response latency EnabledMetric bool // Deprecated // DisabledMetricHostLabel if true, the host label in metric would be pined as '-'. // Allow the user to disable the host label in resty metric when the hostname was // unpredictable. DisabledMetricHostLabel bool // Deprecated // EnabledMetricWithURI if true, metric would record the uri label. Be carefully // when the uri contains the param part may cause the metric exponential growth and OOM, // so you MUST know what you do before enabling the option. EnabledMetricWithURI bool // EnabledTrace if true, use new relic to trace the api request EnabledTrace bool // EnabledOtelTrace if true, use openTelemetry to trace the api request EnabledOtelTrace bool // Config for TLS Client TLSClientConfig *tls.Config // UnifyRequestURIHook allows users to customize the URI in metrics. // If UnifyRequestURIHook is nil, then would not record the uri label. // Be careful, when the uri contains the param part that may cause the metric exponential growth and OOM, // so you MUST handle this situation. // And can't return an empty string. UnifyRequestURIHook func(url *url.URL) string // UnifyRequestHostHook allows users to customize the host in metrics. // If UnifyRequestHostHook is nil, then would not record the host label. // Be careful, when the client be used to request multiple hosts cause the metric exponential growth and OOM, // so you MUST handle this situation. // And can't return an empty string. UnifyRequestHostHook func(url *url.URL) string // ForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero // Dial, DialTLS, or DialContext func or TLSClientConfig is provided. // By default, use of any those fields conservatively disables HTTP/2. // To use a custom dialer or TLS config and still attempt HTTP/2 // upgrades, set this to true. ForceAttemptHTTP2 bool }
func DefaultConfig ¶
func DefaultConfig() *Config
func NewConfig ¶
NewConfig returns a default config if opts is nil, or returns custom config if pass opts
func (*Config) ApplyOptions ¶
ApplyOptions Change config designated values
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option overrides values of Config
func WithDialTimeout ¶
func WithDisabledMetricHostLabel ¶
Deprecated
func WithEnabledMetric ¶
func WithEnabledOtelTrace ¶
func WithEnabledTrace ¶
func WithForceAttemptHTTP2 ¶
func WithIdleConnTimeout ¶
func WithKeepAlive ¶
func WithMaxConnsPerHost ¶
func WithMaxIdleConns ¶
func WithMaxIdleConnsPerHost ¶
func WithTLSClientConfig ¶
func WithTimeout ¶
Click to show internal directories.
Click to hide internal directories.