Documentation ¶
Index ¶
- Constants
- func EnableClientMetrics(ctx context.Context, metricsRegistry metric.MetricsRegistry) error
- func InitConfig(conf config.Section)
- func New(ctx context.Context, staticConfig config.Section) (client *resty.Client, err error)
- func NewWithConfig(ctx context.Context, ffrestyConfig Config) (client *resty.Client)
- func OnAfterResponse(c *resty.Client, resp *resty.Response)
- func OnError(req *resty.Request, err error)
- func OnSuccess(c *resty.Client, resp *resty.Response)
- func RegisterGlobalOnError(onError func(req *resty.Request, err error))
- func RegisterGlobalOnSuccess(onSuccess func(c *resty.Client, resp *resty.Response))
- func WrapRestErr(ctx context.Context, res *resty.Response, err error, key i18n.ErrorMessageKey) error
- type Config
- type HTTPConfig
Constants ¶
const ( // HTTPConfigURL is the url to connect to for this HTTP configuration HTTPConfigURL = "url" // HTTPConfigProxyURL adds a proxy HTTPConfigProxyURL = "proxy.url" // HTTPConfigHeaders adds custom headers to the requests HTTPConfigHeaders = "headers" // HTTPConfigAuthUsername HTTPS Basic Auth configuration - username HTTPConfigAuthUsername = "auth.username" // HTTPConfigAuthPassword HTTPS Basic Auth configuration - secret / password HTTPConfigAuthPassword = "auth.password" // HTTPConfigRetryEnabled whether retry is enabled on the actions performed over this HTTP request (does not disable retry at higher layers) HTTPConfigRetryEnabled = "retry.enabled" // HTTPConfigRetryCount the maximum number of retries HTTPConfigRetryCount = "retry.count" // HTTPConfigRetryInitDelay the initial retry delay HTTPConfigRetryInitDelay = "retry.initWaitTime" // HTTPConfigRetryMaxDelay the maximum retry delay HTTPConfigRetryMaxDelay = "retry.maxWaitTime" // HTTPConfigRetryErrorStatusCodeRegex the regex that the error response status code must match to trigger retry HTTPConfigRetryErrorStatusCodeRegex = "retry.errorStatusCodeRegex" // HTTPConfigRequestTimeout the request timeout HTTPConfigRequestTimeout = "requestTimeout" // HTTPIdleTimeout the max duration to hold a HTTP keepalive connection between calls HTTPIdleTimeout = "idleTimeout" // HTTPMaxIdleConns the max number of idle connections to hold pooled HTTPMaxIdleConns = "maxIdleConns" // HTTPThrottleRequestsPerSecond The average rate at which requests are allowed to pass through over time. Default to RPS // requests over the limit will be blocked using a buffered channel // the blocked time period is not counted in request timeout HTTPThrottleRequestsPerSecond = "throttle.requestsPerSecond" // HTTPThrottleBurst The maximum number of requests that can be made in a short period of time before the RPS throttling kicks in. HTTPThrottleBurst = "throttle.burst" // HTTPMaxConnsPerHost the max number of concurrent connections per host HTTPMaxConnsPerHost = "maxConnsPerHost" // HTTPMaxIdleConnsPerHost the max number of idle connections per host HTTPMaxIdleConnsPerHost = "maxIdleConnsPerHost" // HTTPConnectionTimeout the connection timeout for new connections HTTPConnectionTimeout = "connectionTimeout" // HTTPTLSHandshakeTimeout the TLS handshake connection timeout HTTPTLSHandshakeTimeout = "tlsHandshakeTimeout" // HTTPExpectContinueTimeout see ExpectContinueTimeout in Go docs HTTPExpectContinueTimeout = "expectContinueTimeout" // HTTPPassthroughHeadersEnabled will pass through any HTTP headers found on the context HTTPPassthroughHeadersEnabled = "passthroughHeadersEnabled" // HTTPCustomClient - unit test only - allows injection of a custom HTTP client to resty HTTPCustomClient = "customClient" )
Variables ¶
This section is empty.
Functions ¶
func EnableClientMetrics ¶ added in v1.4.8
func EnableClientMetrics(ctx context.Context, metricsRegistry metric.MetricsRegistry) error
func InitConfig ¶ added in v0.1.4
func New ¶
New creates a new Resty client, using static configuration (from the config file) from a given section in the static configuration
You can use the normal Resty builder pattern, to set per-instance configuration as required.
func NewWithConfig ¶ added in v1.2.15
New creates a new Resty client, using static configuration (from the config file) from a given section in the static configuration
You can use the normal Resty builder pattern, to set per-instance configuration as required.
func OnAfterResponse ¶
func OnAfterResponse(c *resty.Client, resp *resty.Response)
OnAfterResponse when using SetDoNotParseResponse(true) for streaming binary replies, the caller should invoke ffresty.OnAfterResponse on the response manually. The middleware is disabled on this path :-( See: https://github.com/go-resty/resty/blob/d01e8d1bac5ba1fed0d9e03c4c47ca21e94a7e8e/client.go#L912-L948
func RegisterGlobalOnError ¶ added in v1.4.8
func RegisterGlobalOnError(onError func(req *resty.Request, err error))
func RegisterGlobalOnSuccess ¶ added in v1.4.8
func RegisterGlobalOnSuccess(onSuccess func(c *resty.Client, resp *resty.Response))
func WrapRestErr ¶
Types ¶
type Config ¶ added in v1.2.15
type Config struct { URL string `json:"httpURL,omitempty"` HTTPConfig }
type HTTPConfig ¶ added in v1.4.0
type HTTPConfig struct { ProxyURL string `ffstruct:"RESTConfig" json:"proxyURL,omitempty"` HTTPRequestTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"requestTimeout,omitempty"` HTTPIdleConnTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"idleTimeout,omitempty"` HTTPMaxIdleTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"maxIdleTimeout,omitempty"` HTTPConnectionTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"connectionTimeout,omitempty"` HTTPExpectContinueTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"expectContinueTimeout,omitempty"` AuthUsername string `ffstruct:"RESTConfig" json:"authUsername,omitempty"` AuthPassword string `ffstruct:"RESTConfig" json:"authPassword,omitempty"` ThrottleRequestsPerSecond int `ffstruct:"RESTConfig" json:"requestsPerSecond,omitempty"` ThrottleBurst int `ffstruct:"RESTConfig" json:"burst,omitempty"` Retry bool `ffstruct:"RESTConfig" json:"retry,omitempty"` RetryCount int `ffstruct:"RESTConfig" json:"retryCount,omitempty"` RetryInitialDelay fftypes.FFDuration `ffstruct:"RESTConfig" json:"retryInitialDelay,omitempty"` RetryMaximumDelay fftypes.FFDuration `ffstruct:"RESTConfig" json:"retryMaximumDelay,omitempty"` RetryErrorStatusCodeRegex string `ffstruct:"RESTConfig" json:"retryErrorStatusCodeRegex,omitempty"` HTTPMaxIdleConns int `ffstruct:"RESTConfig" json:"maxIdleConns,omitempty"` HTTPMaxConnsPerHost int `ffstruct:"RESTConfig" json:"maxConnsPerHost,omitempty"` HTTPMaxIdleConnsPerHost int `ffstruct:"RESTConfig" json:"maxIdleConnsPerHost,omitempty"` HTTPPassthroughHeadersEnabled bool `ffstruct:"RESTConfig" json:"httpPassthroughHeadersEnabled,omitempty"` HTTPHeaders fftypes.JSONObject `ffstruct:"RESTConfig" json:"headers,omitempty"` HTTPTLSHandshakeTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"tlsHandshakeTimeout,omitempty"` HTTPCustomClient interface{} `json:"-"` TLSClientConfig *tls.Config `json:"-"` // should be built from separate TLSConfig using fftls utils OnCheckRetry func(res *resty.Response, err error) bool `json:"-"` // response could be nil on err OnBeforeRequest func(req *resty.Request) error `json:"-"` // called before each request, even retry }
HTTPConfig is all the optional configuration separate to the URL you wish to invoke. This is JSON serializable with docs, so you can embed it into API objects.