Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addon/retry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ retry.NewExponentialBackoff()
## Custom Config

```go
import "time"

retry.NewExponentialBackoff(retry.Config{
InitialInterval: 2 * time.Second,
MaxBackoffTime: 64 * time.Second,
Expand Down
136 changes: 61 additions & 75 deletions docs/addon/retry.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,45 @@
<!-- Code generated by gomarkdoc. DO NOT EDIT -->

---

Check failure on line 3 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

First line in a file should be a top-level heading

docs/addon/retry.md:3 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "---"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md041.md
id: retry

Check failure on line 4 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Headings should be surrounded by blank lines

docs/addon/retry.md:4 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "id: retry"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md
---

# Retry Addon

The Retry addon for [Fiber](https://github.com/gofiber/fiber) retries failed network operations using exponential
backoff with jitter. It repeatedly invokes a function until it succeeds or the maximum number of attempts is
exhausted. Jitter at each step breaks client synchronization and helps avoid collisions. If all attempts fail, the
addon returns an error.

## Table of Contents

Check failure on line 7 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines

docs/addon/retry.md:7 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md012.md
- [Signatures](#signatures)
- [Examples](#examples)
- [Default Config](#default-config)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config Example](#default-config-example)

## Signatures
# retry

Check failure on line 8 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading style

docs/addon/retry.md:8 MD003/heading-style Heading style [Expected: setext; Actual: atx] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md

```go
func NewExponentialBackoff(config ...retry.Config) *retry.ExponentialBackoff
import "github.com/gofiber/fiber/v3/addon/retry"
```

## Examples
## Index

Check failure on line 14 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading style

docs/addon/retry.md:14 MD003/heading-style Heading style [Expected: setext; Actual: atx] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md

```go
package main

import (
"fmt"

"github.com/gofiber/fiber/v3/addon/retry"
"github.com/gofiber/fiber/v3/client"
)

func main() {
expBackoff := retry.NewExponentialBackoff(retry.Config{})

// Local variables used inside Retry
var resp *client.Response
var err error

// Retry a network request and return an error to signal another attempt
err = expBackoff.Retry(func() error {
client := client.New()
resp, err = client.Get("https://gofiber.io")
if err != nil {
return fmt.Errorf("GET gofiber.io failed: %w", err)
}
if resp.StatusCode() != 200 {
return fmt.Errorf("GET gofiber.io did not return 200 OK")
}
return nil
})

// If all retries failed, panic
if err != nil {
panic(err)
}
fmt.Printf("GET gofiber.io succeeded with status code %d\n", resp.StatusCode())
}
```
- [Variables](<#variables>)
- [type Config](<#Config>)
- [type ExponentialBackoff](<#ExponentialBackoff>)
- [func NewExponentialBackoff\(config ...Config\) \*ExponentialBackoff](<#NewExponentialBackoff>)
- [func \(e \*ExponentialBackoff\) Retry\(f func\(\) error\) error](<#ExponentialBackoff.Retry>)

## Default Config

Check failure on line 22 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines

docs/addon/retry.md:22 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md012.md
```go
retry.NewExponentialBackoff()
```
## Variables

Check failure on line 23 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading style

docs/addon/retry.md:23 MD003/heading-style Heading style [Expected: setext; Actual: atx] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md

## Custom Config
<a name="DefaultConfig"></a>DefaultConfig is the default config for retry.

```go
retry.NewExponentialBackoff(retry.Config{
InitialInterval: 2 * time.Second,
MaxBackoffTime: 64 * time.Second,
var DefaultConfig = Config{
InitialInterval: 1 * time.Second,
MaxBackoffTime: 32 * time.Second,
Multiplier: 2.0,
MaxRetryCount: 15,
})
MaxRetryCount: 10,
// contains filtered or unexported fields
}
```

## Config
<a name="Config"></a>
## type Config

Check failure on line 38 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Headings should be surrounded by blank lines

docs/addon/retry.md:38 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "## type Config"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md

Check failure on line 38 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading style

docs/addon/retry.md:38 MD003/heading-style Heading style [Expected: setext; Actual: atx] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md

Config defines the config for addon.

```go
// Config defines the config for addon.
type Config struct {
// InitialInterval defines the initial time interval for backoff algorithm.
//
Expand All @@ -107,18 +62,49 @@
//
// Optional. Default: 10
MaxRetryCount int
// contains filtered or unexported fields
}
```

## Default Config Example
<a name="ExponentialBackoff"></a>
## type ExponentialBackoff

Check failure on line 70 in docs/addon/retry.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading style

docs/addon/retry.md:70 MD003/heading-style Heading style [Expected: setext; Actual: atx] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md

ExponentialBackoff is a retry mechanism for retrying some calls.

```go
// DefaultConfig is the default config for retry.
var DefaultConfig = Config{
InitialInterval: 1 * time.Second,
MaxBackoffTime: 32 * time.Second,
Multiplier: 2.0,
MaxRetryCount: 10,
currentInterval: 1 * time.Second,
type ExponentialBackoff struct {
// InitialInterval is the initial time interval for backoff algorithm.
InitialInterval time.Duration

// MaxBackoffTime is the maximum time duration for backoff algorithm. It limits
// the maximum sleep time.
MaxBackoffTime time.Duration

// Multiplier is a multiplier number of the backoff algorithm.
Multiplier float64

// MaxRetryCount is the maximum number of retry count.
MaxRetryCount int
// contains filtered or unexported fields
}
```

<a name="NewExponentialBackoff"></a>
### func NewExponentialBackoff

```go
func NewExponentialBackoff(config ...Config) *ExponentialBackoff
```

NewExponentialBackoff creates a ExponentialBackoff with default values.

<a name="ExponentialBackoff.Retry"></a>
### func \(\*ExponentialBackoff\) Retry

```go
func (e *ExponentialBackoff) Retry(f func() error) error
```

Retry is the core logic of the retry mechanism. If the calling function returns nil as an error, then the Retry method is terminated with returning nil. Otherwise, if all function calls are returned error, then the method returns this error.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
Loading
Loading