{"id":25847645,"url":"https://github.com/devjefster/goretry","last_synced_at":"2026-05-08T23:19:13.172Z","repository":{"id":277754936,"uuid":"933383908","full_name":"devjefster/GoRetry","owner":"devjefster","description":"This Go library provides a robust **retry mechanism** with support for:","archived":false,"fork":false,"pushed_at":"2025-02-15T21:02:25.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T22:18:22.312Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devjefster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-15T20:28:44.000Z","updated_at":"2025-02-15T21:02:28.000Z","dependencies_parsed_at":"2025-02-15T22:18:23.977Z","dependency_job_id":"646d52a4-0714-4044-8300-9a5d67155c71","html_url":"https://github.com/devjefster/GoRetry","commit_stats":null,"previous_names":["devjefster/goretry"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjefster%2FGoRetry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjefster%2FGoRetry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjefster%2FGoRetry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjefster%2FGoRetry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devjefster","download_url":"https://codeload.github.com/devjefster/GoRetry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241353935,"owners_count":19949130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-01T10:33:33.041Z","updated_at":"2025-11-26T04:01:41.136Z","avatar_url":"https://github.com/devjefster.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Go Retry Library\n\n## 📌 Overview\n\nThis Go library provides a robust **retry mechanism** with support for:\n\n-   ✅ **Exponential, linear, and fixed backoff strategies**\n-   ✅ **Custom retry logic** with user-defined functions\n-   ✅ **Circuit breaker protection** to prevent excessive retries\n-   ✅ **Retryable HTTP errors** and generic error handling\n-   ✅ **Context-aware retries** with timeout and cancellation support\n\n## 🚀 Features\n\n-   **Multiple Backoff Strategies**: Fixed, Linear, Exponential, Custom\n-   **Circuit Breaker Support**: Prevents retrying failures indefinitely\n-   **Flexible Configuration**: Customize retry behavior easily\n-   **Retry Middleware**: Wraps HTTP handlers for automatic retries\n-   **Optimized Performance**: Uses maps for fast lookup of retryable errors\n\n----------\n\n## ⚙ Installation\n\n```sh\n  go get github.com/devjefster/GoRetry\n\n```\n\n----------\n\n## 🛠 Usage\n\n### 🔹 Basic Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/devjefster/GoRetry\"\n)\n\nfunc unstableOperation() error {\n\tif time.Now().UnixNano()%2 == 0 {\n\t\treturn errors.New(\"temporary failure\")\n\t}\n\treturn nil\n}\n\nfunc main() {\n\tcfg := retry.DefaultConfig\n\tcfg.MaxRetries = 3\n\n\tctx := context.Background()\n\terr := retry.Retry(ctx, unstableOperation, cfg)\n\tif err != nil {\n\t\tfmt.Println(\"Operation failed:\", err)\n\t} else {\n\t\tfmt.Println(\"Operation succeeded\")\n\t}\n}\n\n```\n\n----------\n\n### 🔹 Using Circuit Breaker\n\n```go\ncfg := retry.Config{\n\tMaxRetries:              5,\n\tCircuitBreakerThreshold: 2, // Stops retrying after 2 consecutive failures\n}\n\n```\n\n----------\n\n### 🔹 Custom Backoff Function\n\n```go\ncfg := retry.Config{\n\tBackoffStrategy: retry.CustomBackoff,\n\tCustomBackoffFunc: func(attempt int) time.Duration {\n\t\treturn time.Duration(attempt) * 200 * time.Millisecond\n\t},\n}\n\n```\n\n----------\n\n### 🔹 HTTP Retry Middleware\n\nWrap your HTTP handlers with retry logic:\n\n```go\nmux := http.NewServeMux()\nmux.Handle(\"/data\", myHandler)\n\ncfg := retry.DefaultConfig\ncfg.RetryableStatusCodes = []int{500, 502, 503, 504}\nwrappedHandler := retry.RetryMiddleware(cfg, mux)\n\nhttp.ListenAndServe(\":8080\", wrappedHandler)\n\n```\n\n----------\n\n## 🧪 Running Tests\n\n```sh\n  go test -v ./...\n\n```\n\n----------\n\n## 📜 License\n\nMIT License\n\n----------\n\n## 🤝 Contributing\n\n1.  Fork the repo\n2.  Create a new branch (`git checkout -b feature-name`)\n3.  Commit your changes (`git commit -m 'Added new feature'`)\n4.  Push to the branch (`git push origin feature-name`)\n5.  Open a Pull Request 🎉\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjefster%2Fgoretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevjefster%2Fgoretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjefster%2Fgoretry/lists"}