https://github.com/ilyasyoy/go-retry
Simple package to do retries in Go
https://github.com/ilyasyoy/go-retry
go golang retry-library
Last synced: 6 months ago
JSON representation
Simple package to do retries in Go
- Host: GitHub
- URL: https://github.com/ilyasyoy/go-retry
- Owner: IlyasYOY
- License: mit
- Created: 2024-03-22T15:28:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-23T17:30:35.000Z (over 1 year ago)
- Last Synced: 2025-02-14T07:51:23.238Z (8 months ago)
- Topics: go, golang, retry-library
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-retry
Simple package to do retries in Go.
You can consider this a practice of *fluent API* in Go.Maybe used to abstract away of the retry logic so you wont deal with time
calculations at domain level tests.```go
// complicated.go
type ComplicatedService struct {
retry goretry.Retryer[any]
}func (s *ComplicatedService) Do() error {
return retry.Retry(func () error {
// do something
})
}// complicated_test.go
func TestReallyHardWithoutRetryLogic(t *testing.T) {
service := &ComplicatedService{
// So your test will simple call code until success
retry: goretry.New[any](
goretry.WithInitialDelay(0)
),
}
}
```## Example
```go
retryer := goretry.New[int](
goretry.WithInitialDelay(time.Second),
goretry.WithIncreasingDelay(time.Second),
)error := retryer.Retry(func() error {
// some loginc
})result, error := retryer.RetryReturn(func() (int, error) {
// some logic
return value
})
```More examples can be found in [tests](./retry_test.go).
You also can combine `DelayCalculators`,
examples are in [tests](./delay_test.go).