Documentation
¶
Index ¶
- func Client(options ...CustomOption) *http.Client
- func OperationalEndpointFilter(r *http.Request) bool
- type CustomOption
- func WithCBConsecutiveFailures(failures uint32) CustomOption
- func WithCBHTTPSatusCodeMax(d int) CustomOption
- func WithCBMaxRequests(d uint32) CustomOption
- func WithCBTimeout(d time.Duration) CustomOption
- func WithCircuitBreakerStats(stats *circuitbreaker.Stats, moduleName string) CustomOption
- func WithConcurrency(c int) CustomOption
- func WithDialer(...) CustomOption
- func WithDisableKeepAlive(d bool) CustomOption
- func WithEnableCircuitBreaker(enable bool) CustomOption
- func WithInsecureSkipVerify(d bool) CustomOption
- func WithKeepAliveTimeout(d time.Duration) CustomOption
- func WithProxyHost(d string) CustomOption
- func WithRetryMax(c int) CustomOption
- func WithRetryWaitMax(d time.Duration) CustomOption
- func WithRetryWaitMin(d time.Duration) CustomOption
- func WithRetryableStats(stats *retryable.Stats, moduleName string) CustomOption
- func WithTimeout(d time.Duration) CustomOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
func Client(options ...CustomOption) *http.Client
Client creates a http.Client with configurable options for timeout, concurrency, retries, keep-alive, and circuit breaker.
Example ¶
httpClient := Client()
response, err := httpClient.Get("http://detectportal.firefox.com")
if err != nil {
fmt.Println("Error:", err.Error())
return
}
if response.StatusCode != http.StatusOK {
fmt.Println("Error:", "status %s", response.Status)
return
}
content, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("Error:", err.Error())
return
}
_ = response.Body.Close()
fmt.Println(string(content))
Output: success
func OperationalEndpointFilter ¶
OperationalEndpointFilter filters out requests to operational endpoints like "health", and "ready".
Types ¶
type CustomOption ¶
type CustomOption func(*customConfig)
func WithCBConsecutiveFailures ¶
func WithCBConsecutiveFailures(failures uint32) CustomOption
WithCBConsecutiveFailures set circuit breaker consecutive failures/errors.
func WithCBHTTPSatusCodeMax ¶
func WithCBHTTPSatusCodeMax(d int) CustomOption
WithCBHTTPSatusCodeMax is the HTTP status code from which the CircuitBreaker counts errors.
func WithCBMaxRequests ¶
func WithCBMaxRequests(d uint32) CustomOption
WithCBMaxRequests is the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, the CircuitBreaker allows only 1 request.
func WithCBTimeout ¶
func WithCBTimeout(d time.Duration) CustomOption
WithCBTimeout set circuit breaker timeout, is the period of the open state, after which the state of the CircuitBreaker becomes half-open. If WithTimeout is less than or equal to 0, the timeout value of the CircuitBreaker is set to 60 seconds.
func WithCircuitBreakerStats ¶
func WithCircuitBreakerStats(stats *circuitbreaker.Stats, moduleName string) CustomOption
WithCircuitBreakerStats set stats and module name for metrics OTEL.
func WithConcurrency ¶
func WithConcurrency(c int) CustomOption
WithConcurrency set max conns and idles per host.
func WithDialer ¶
func WithDialer(dialer func(ctx context.Context, network string, addr string) (net.Conn, error)) CustomOption
WithDialer set dialer.
func WithDisableKeepAlive ¶
func WithDisableKeepAlive(d bool) CustomOption
WithDisableKeepAlive set true to disable keep-alive.
func WithEnableCircuitBreaker ¶
func WithEnableCircuitBreaker(enable bool) CustomOption
WithEnableCircuitBreaker for activate circuit breaker.
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify(d bool) CustomOption
WithInsecureSkipVerify controls whether a client verifies the server's certificate chain and host name.
func WithKeepAliveTimeout ¶
func WithKeepAliveTimeout(d time.Duration) CustomOption
WithKeepAliveTimeout set time duration for keep alive timeout.
func WithProxyHost ¶
func WithProxyHost(d string) CustomOption
func WithRetryWaitMax ¶
func WithRetryWaitMax(d time.Duration) CustomOption
WithRetryWaitMax set time duration for maximum duration for retry.
func WithRetryWaitMin ¶
func WithRetryWaitMin(d time.Duration) CustomOption
WithRetryWaitMin set time duration for minimum duration for retry.
func WithRetryableStats ¶
func WithRetryableStats(stats *retryable.Stats, moduleName string) CustomOption
WithRetryableStats set stats and module name for metrics OTEL.
func WithTimeout ¶
func WithTimeout(d time.Duration) CustomOption
WithTimeout set time duration for timeout.