Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shirokovnv/circuit_breaker
Circuit-breaker pattern, written in Go
https://github.com/shirokovnv/circuit_breaker
circuit-breaker go pattern
Last synced: 1 day ago
JSON representation
Circuit-breaker pattern, written in Go
- Host: GitHub
- URL: https://github.com/shirokovnv/circuit_breaker
- Owner: shirokovnv
- License: mit
- Created: 2023-08-17T13:13:52.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-08-18T10:15:03.000Z (over 1 year ago)
- Last Synced: 2024-06-19T21:00:08.013Z (5 months ago)
- Topics: circuit-breaker, go, pattern
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Circuit Breaker
Implements [circuit-breaker pattern][link-pattern] with [Golang][link-go]
Inpsired by [sony/gobreaker][link-inspired]
## Dependencies
- [Go][link-go] >= 1.19
- [Make][link-make]## Architecture
![Diagram](circuit_breaker.png)
## Example
```go
func main() {
config := circuit_breaker.Config{
Name: "Circuit Breaker",
ReadyToTrip: func(counts circuit_breaker.Counts) bool {
failureRatio := float64(counts.TotalFailures) / float64(counts.Requests)
return counts.Requests >= 3 && failureRatio >= 0.7
},
OnStateChange: func(name string, from, to circuit_breaker.State) {
fmt.Printf("%s: state changed from %s to %s", name, from, to)
},
}cb := circuit_breaker.NewCircuitBreaker(config)
msg, err := cb.Execute(func() (interface{}, error) {
// your actual service call here...
})
}
```See [example][link-example] for details.
## License
MIT. Please see the [license file](license.md) for more information.
[link-go]: https://go.dev/
[link-make]: https://www.gnu.org/software/make/manual/make.html
[link-inspired]: https://github.com/sony/gobreaker/
[link-example]: /example/main.go
[link-pattern]: https://microservices.io/patterns/reliability/circuit-breaker.html