Skip to content

Commit

Permalink
move package to root of repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranielly Ferreira committed Jul 27, 2024
1 parent d3a3330 commit 96db203
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 130 deletions.
102 changes: 101 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
# Go Packages
# retryable

## Introduction

The retryable package provides a robust set of functions designed to simplify the retry logic in your Go applications. Whether you're dealing with transient network issues, intermittent service failures, or any situation where an operation might need to be attempted multiple times before it succeeds, retryable has got you covered.

## Installation

To use the retryable package in your project, execute the following command:

```bash
go get github.com/raniellyferreira/go-retryable
```

## Usage Examples

Here's how you can use retryable to retry a function that might fail due to a transient error:

```go
import "github.com/raniellyferreira/go-retryable"

func mightFailOperation() (int, error) {
// Your code here that might fail
}

result, err := retryable.MustRetry(mightFailOperation)
if err != nil {
log.Fatalf("Operation failed after retries: %v", err)
}
```

For more advanced usage with custom retry logic:

```go
import "github.com/raniellyferreira/go-retryable"

func mightFailOperation() (string, error) {
// Your code here that might fail
}

isRetryable := func(err error) bool {
// Define your custom logic to determine if an error is retryable
}

result, err := retryable.RetryWithCustomCheck(mightFailOperation, 5, 2*time.Second, isRetryable)
if err != nil {
log.Fatalf("Operation failed after retries: %v", err)
}
```

## Configuration Options

You can configure the retryable package to suit your needs. Here's an example:

```go
retryable.DefaultMaxAttempts = 5
retryable.DefaultDelay = 2 * time.Second
```

## Logger Configuration

The `retryable` package provides a custom logging feature that allows you to specify how log messages are output. By default, the package uses Go's standard logger, but you can easily customize this to integrate with your own logging infrastructure.

### Using the Default Logger

By default, `retryable` will output log messages to the standard logger provided by Go's `log` package. You don't need to perform any additional configuration to use this default behavior.

### Customizing Log Output

To redirect log messages from `retryable` to Logrus, provide a custom logging function that matches the signature of `log.Printf`. Below is an example using Logrus' `Warnf` method for warning level messages:

```go
package main

import (
"github.com/sirupsen/logrus"
"github.com/raniellyferreira/go-retryable"
)

func main() {
// Initialize a new Logrus logger.
logger := logrus.New()

// Configure retryable to use the custom logger.
retryable.SetLoggerWriter(logger.Warnf)

// Now, all retry logs will be handled by Logrus with warning level.
}
```

This configuration routes all retry-related log messages through Logrus, allowing you to take advantage of Logrus' structured logging and level-specific logging methods.

Remember to import the Logrus package and configure it according to your application's requirements before setting it as the logger for `retryable`.

## Contributing

Contributions to retryable are welcome! Feel free to fork the repository, make your changes, and submit a pull request.

## License

This project is licensed under the MIT License - see the LICENSE file for details.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package gopackages
package retryable
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/raniellyferreira/go-packages
module github.com/raniellyferreira/go-retryable

go 1.22
File renamed without changes.
21 changes: 0 additions & 21 deletions retryable/LICENCE

This file was deleted.

101 changes: 0 additions & 101 deletions retryable/README.md

This file was deleted.

1 change: 0 additions & 1 deletion retryable/doc.go

This file was deleted.

3 changes: 0 additions & 3 deletions retryable/go.mod

This file was deleted.

2 changes: 1 addition & 1 deletion retryable/retryable_test.go → retryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/raniellyferreira/go-packages/retryable"
"github.com/raniellyferreira/go-retryable"
)

func TestMustRetrySuccess(t *testing.T) {
Expand Down

0 comments on commit 96db203

Please sign in to comment.