ffresty

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
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"
	// 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"
	// HTTPMaxConnsPerHost the max number of concurrent connections
	HTTPMaxConnsPerHost = "maxConnsPerHost"
	// 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 InitConfig added in v0.1.4

func InitConfig(conf config.Section)

func New

func New(ctx context.Context, staticConfig config.Section) (client *resty.Client, err error)

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

func NewWithConfig(ctx context.Context, ffrestyConfig Config) (client *resty.Client)

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 WrapRestErr

func WrapRestErr(ctx context.Context, res *resty.Response, err error, key i18n.ErrorMessageKey) error

Types

type Config added in v1.2.15

type Config struct {
	URL                           string                                    `json:"httpURL,omitempty"`
	ProxyURL                      string                                    `json:"proxyURL,omitempty"`
	HTTPRequestTimeout            time.Duration                             `json:"requestTimeout,omitempty"`
	HTTPIdleConnTimeout           time.Duration                             `json:"idleTimeout,omitempty"`
	HTTPMaxIdleTimeout            time.Duration                             `json:"maxIdleTimeout,omitempty"`
	HTTPConnectionTimeout         time.Duration                             `json:"connectionTimeout,omitempty"`
	HTTPExpectContinueTimeout     time.Duration                             `json:"expectContinueTimeout,omitempty"`
	AuthUsername                  string                                    `json:"authUsername,omitempty"`
	AuthPassword                  string                                    `json:"authPassword,omitempty"`
	Retry                         bool                                      `json:"retry,omitempty"`
	RetryCount                    int                                       `json:"retryCount,omitempty"`
	RetryInitialDelay             time.Duration                             `json:"retryInitialDelay,omitempty"`
	RetryMaximumDelay             time.Duration                             `json:"retryMaximumDelay,omitempty"`
	HTTPMaxIdleConns              int                                       `json:"maxIdleConns,omitempty"`
	HTTPMaxConnsPerHost           int                                       `json:"maxConnsPerHost,omitempty"`
	HTTPPassthroughHeadersEnabled bool                                      `json:"httpPassthroughHeadersEnabled,omitempty"`
	HTTPHeaders                   fftypes.JSONObject                        `json:"headers,omitempty"`
	TLSClientConfig               *tls.Config                               `json:"tlsClientConfig,omitempty"`
	HTTPTLSHandshakeTimeout       time.Duration                             `json:"tlsHandshakeTimeout,omitempty"`
	HTTPCustomClient              interface{}                               `json:"httpCustomClient,omitempty"`
	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
}

func GenerateConfig added in v1.2.15

func GenerateConfig(ctx context.Context, conf config.Section) (*Config, error)

Jump to

Keyboard shortcuts

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