ffresty

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 18 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"
	// 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"
	// 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"`
	HTTPConfig
}

func GenerateConfig added in v1.2.15

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

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"`
	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"`
	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.

Jump to

Keyboard shortcuts

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