Documentation
¶
Index ¶
- func AlwaysRetry(_ error) bool
- func CloseResponseBody(response *http.Response)
- func ConstructBaseAddress(tlsEnabled bool, hostPort string) string
- func CreateCACertPool(caCertBundlePath string) (*x509.CertPool, error)
- func CreateTLSConfig(tlsEnabledFn IsTLSEnabledFn, serverName, caCertPath string, keyPair *KeyPair) (*tls.Config, error)
- func ResponseHasOKCode(response *http.Response) bool
- type CanRetryPredicate
- type IsTLSEnabledFn
- type KeyPair
- type Result
- type RetriableFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlwaysRetry ¶
AlwaysRetry ignores the error and always returns true. This can be used as a CanRetryPredicate when using Retry if a retry is required irrespective of any error during the invocation of the function.
func CloseResponseBody ¶
CloseResponseBody closes the response body if the response is not nil. As per https://pkg.go.dev/net/http - The http Client and Transport guarantee that Body is always non-nil, even on responses without a body or responses with a zero-length body. It is the caller's responsibility to close Body. The default HTTP client's Transport may not reuse HTTP/1.x "keep-alive" TCP connections if the Body is not read to completion and closed.
func ConstructBaseAddress ¶
ConstructBaseAddress creates a base address selecting a scheme based on tlsEnabled and using hostPort.
func CreateCACertPool ¶
CreateCACertPool creates a CA cert pool gives a CA cert bundle
func CreateTLSConfig ¶
func CreateTLSConfig(tlsEnabledFn IsTLSEnabledFn, serverName, caCertPath string, keyPair *KeyPair) (*tls.Config, error)
CreateTLSConfig creates a TLS Config to be used for TLS communication.
func ResponseHasOKCode ¶
ResponseHasOKCode checks if the response is one of the accepted OK responses.
Types ¶
type CanRetryPredicate ¶
CanRetryPredicate provides a predicate whose return value decides if an error can be ignored for the next retry.
type IsTLSEnabledFn ¶
type IsTLSEnabledFn func() bool
IsTLSEnabledFn returns true if TLS is enabled and false otherwise.
type KeyPair ¶
type KeyPair struct { // CertPath is the path to the certificate CertPath string // KeyPath is the path to the private key KeyPath string }
KeyPair is a collection of paths one for the certificate and another for the key. This is used to configure certificate-key pair when configuring TLS config.
type Result ¶
Result encapsulates the result of retrying a function via Retry.
func Retry ¶
func Retry[T any](ctx context.Context, logger *zap.Logger, operation string, fn RetriableFunc[T], numAttempts int, backOff time.Duration, canRetryFn CanRetryPredicate) Result[T]
Retry will retry invoking the given function `fn` a max of `numAttempts` with a back off between successive attempts. If an invocation of the function returns an error then it will check it can proceed with the retry by evaluating via `canRetryFn`. A Result containing the return value if function invocation was successful or an error if the function was not successful will be returned to the caller. The caller can check if the Result is an error by invoking Result.IsErr function.
type RetriableFunc ¶
RetriableFunc is any function that should be retried. It returns any T and an error.