retryableRequest

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

README

retryableRequest

import "github.com/greenbone/opensight-golang-libraries/pkg/retryableRequest"

Package retryableRequest provides a function to retry an http request up to a configured number of retries. It builds on [retryablehttp], but works with the default [http.Client].

Index

func DeepCopyRequest

func DeepCopyRequest(request *http.Request) (copy *http.Request, err error)

DeepCopyRequest returns a deep copy of the request. The context of the original request is placed by context.Background. An error indicates a problem with the http request. In that case the passed request should no longer be used.

func ExecuteRequestWithRetry

func ExecuteRequestWithRetry(ctx context.Context, client *http.Client, request *http.Request, maxRetries int, retryWaitMin, retryWaitMax time.Duration) (*http.Response, error)

ExecuteRequestWithRetry executes the given request via the passed http client and retries on failures. An error is only returned if there was a non retryable error or the maximum number of retries was reached. It uses the retry policy of [retryablehttp.ErrorPropagatedRetryPolicy] and exponential backoff from [retryablehttp.DefaultBackoff].

func IsOk

func IsOk(statusCode int) bool

IsOk returns true on a 2xx http status code

Generated by gomarkdoc

Documentation

Overview

Package retryableRequest provides a function to retry an http request up to a configured number of retries. It builds on retryablehttp, but works with the default http.Client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopyRequest

func DeepCopyRequest(request *http.Request) (copy *http.Request, err error)

DeepCopyRequest returns a deep copy of the request. The context of the original request is placed by context.Background. An error indicates a problem with the http request. In that case the passed request should no longer be used.

func ExecuteRequestWithRetry

func ExecuteRequestWithRetry(ctx context.Context, client *http.Client, request *http.Request,
	maxRetries int, retryWaitMin, retryWaitMax time.Duration,
) (*http.Response, error)

ExecuteRequestWithRetry executes the given request via the passed http client and retries on failures. An error is only returned if there was a non retryable error or the maximum number of retries was reached. It uses the retry policy of retryablehttp.ErrorPropagatedRetryPolicy and exponential backoff from retryablehttp.DefaultBackoff.

func IsOk

func IsOk(statusCode int) bool

IsOk returns true on a 2xx http status code

Types

This section is empty.

Jump to

Keyboard shortcuts

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