micro-wrapper-breaker-sony/gobreaker.go
2020-10-02 13:04:21 +03:00

29 lines
681 B
Go

package gobreaker
import (
"github.com/micro/go-micro/client"
"github.com/sony/gobreaker"
"context"
)
type clientWrapper struct {
cb *gobreaker.CircuitBreaker
client.Client
}
func (c *clientWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
_, err := c.cb.Execute(func() (interface{}, error) {
cerr := c.Client.Call(ctx, req, rsp, opts...)
return nil, cerr
})
return err
}
// NewClientWrapper takes a *gobreaker.CircuitBreaker and returns a client Wrapper.
func NewClientWrapper(cb *gobreaker.CircuitBreaker) client.Wrapper {
return func(c client.Client) client.Client {
return &clientWrapper{cb, c}
}
}