https://github.com/tomiok/clipper
Clipper is an plug-and-play, easy to use circuit breaker library. Based on Netflix Hystrix. Give a try for fast, secure and a non-dependency piece of software.
https://github.com/tomiok/clipper
circuit-breaker go golang hystrix-based library microservices pattern
Last synced: 11 months ago
JSON representation
Clipper is an plug-and-play, easy to use circuit breaker library. Based on Netflix Hystrix. Give a try for fast, secure and a non-dependency piece of software.
- Host: GitHub
- URL: https://github.com/tomiok/clipper
- Owner: tomiok
- License: mit
- Created: 2021-04-16T06:21:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-12-11T06:44:51.000Z (over 4 years ago)
- Last Synced: 2024-06-20T03:43:27.369Z (about 2 years ago)
- Topics: circuit-breaker, go, golang, hystrix-based, library, microservices, pattern
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clipper - circuit breaker
### Lightweight circuit breaker tool, inspired in hystrix from Netflix.
----
This is a simple, dependency free, circuit breaker library. Super easy to use.
You could find also some basic statistics and a handler according to the std lib to expose, given the name of the
command.
```go
clipper.Do(&clipper.Configs{Name: "my_command"}, func() error {
_, err := http.Get("http://www.google.com/robots.txt")
return err
}, nil)
```
Do use 3 args,
1. The Config
2. Operational function
3. Fallback function
And in this case you also have 2 different ways to call the clipper , sync and async, could check out in the
examples folder.
The config should have the name and the max duration expressed in seconds.
The Function to operate,.
The fallback function, is not necessary at all.
### Wait the response
```go
out := make(chan bool, 1)
var res *http.Response
valChan := clipper.Do(&clipper.Configs{Name: "my_command"}, func() error {
r, err := http.Get("http://www.google.com/robots.txt")
res = r
out <- true
return err
}, nil)
select {
case <-out:
value := <-valChan
if value == 0 {
fmt.Println("no errors")
} else {
fmt.Println("some errors here")
}
}
fmt.Println(res)
```
### No wait to the response
```go
clipper.Do(&clipper.Configs{Name: "my_command"}, func() error {
r, err := http.Get("http://www.google.com/robots.txt")
res = r
return err
}, nil)
clipper.FillStats("my_command", true)
```
### Web
Check the function `ExposeMetrics()` and get all the metrics info. You must provide a valid command name. In the
URL like:
`localhost:8080/metrics?c=my_command`
---
### Tests
```shell
go test -v .
```