{"id":15048269,"url":"https://github.com/github/circuitbreaker","last_synced_at":"2025-10-04T08:31:16.141Z","repository":{"id":19239164,"uuid":"22474154","full_name":"github/circuitbreaker","owner":"github","description":"Circuit Breakers in Go","archived":true,"fork":true,"pushed_at":"2014-07-31T19:26:15.000Z","size":183,"stargazers_count":27,"open_issues_count":0,"forks_count":11,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-09-25T21:09:44.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rubyist/circuitbreaker","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github.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}},"created_at":"2014-07-31T15:26:40.000Z","updated_at":"2024-07-31T03:22:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/github/circuitbreaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcircuitbreaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcircuitbreaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcircuitbreaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcircuitbreaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/circuitbreaker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219876581,"owners_count":16554769,"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":"2024-09-24T21:10:01.717Z","updated_at":"2025-10-04T08:31:10.890Z","avatar_url":"https://github.com/github.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# circuitbreaker\n\nCircuitbreaker provides an easy way to use the Circuit Breaker pattern in a\nGo program.\n\nCircuit breakers are typically used when your program makes remote calls.\nRemote calls can often hang for a while before they time out. If your\napplication makes a lot of these requests, many resources can be tied\nup waiting for these time outs to occur. A circuit breaker wraps these\nremote calls and will trip after a defined amount of failures or time outs\noccur. When a circuit breaker is tripped any future calls will avoid making\nthe remote call and return an error to the client. In the meantime, the\ncircuit breaker will periodically allow some calls to be tried again and\nwill close the circuit if those are successful.\n\nYou can read more about this pattern and how it's used at:\n- [Martin Fowler's bliki](http://martinfowler.com/bliki/CircuitBreaker.html)\n- [The Netflix Tech Blog](http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html)\n- [Release It!](http://pragprog.com/book/mnee/release-it)\n\n[![GoDoc](https://godoc.org/github.com/rubyist/circuitbreaker?status.svg)](https://godoc.org/github.com/rubyist/circuitbreaker)\n\n## Installation\n\n```\n  go get github.com/rubyist/circuitbreaker\n```\n\n## Examples\n\nHere is a quick example of what circuitbreaker provides\n\n```go\n// Creates a circuit breaker that will trip if the function fails 10 times\ncb := NewThresholdBreaker(10)\n\ncb.BreakerTripped = func() {\n\t// This function will be called every time the circuit breaker moves\n\t// from reset to tripped.\n}\n\ncb.BreakerReset = func() {\n\t// This function will be called every time the circuit breaker moves\n\t// from tripped to reset.\n}\n\ncb.Call(func() error {\n\t// This is where you'll do some remote call\n\t// If it fails, return an error\n})\n```\n\nCircuitbreaker can also wrap a time out around the remote call.\n\n```go\n// Creates a circuit breaker that will trip after 10 failures or time outs\n// using a time out of 5 seconds\ncb := NewTimeoutBreaker(Time.Second * 5, 10)\n\n// Proceed as above\n\n```\n\nCircuitbreaker also provides a wrapper around `http.Client` that will wrap a\ntime out around any request.\n\n```go\n// Passing in nil will create a regular http.Client.\n// You can also build your own http.Client and pass it in\nclient := NewHTTPClient(time.Second * 5, 10, nil)\nclient.BreakerTripped = func() {\n\t// Perhaps notify your monitoring system\n}\nclient.BreakerReset = func() {\n\t// Perhaps notify your monitoring system\n}\n\nresp, err := client.Get(\"http://example.com/resource.json\")\n```\n\nSee the godoc for more examples.\n\n## Bugs, Issues, Feedback\n\nRight here on GitHub: [https://github.com/rubyist/circuitbreaker](https://github.com/rubyist/circuitbreaker)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fcircuitbreaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Fcircuitbreaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fcircuitbreaker/lists"}