2016-03-15 21:38:16 +03:00
|
|
|
package hystrix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/afex/hystrix-go/hystrix"
|
|
|
|
"github.com/micro/go-micro/client"
|
|
|
|
|
2018-03-03 15:28:44 +03:00
|
|
|
"context"
|
2016-03-15 21:38:16 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type clientWrapper struct {
|
|
|
|
client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *clientWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
|
|
|
return hystrix.Do(req.Service()+"."+req.Method(), func() error {
|
|
|
|
return c.Client.Call(ctx, req, rsp, opts...)
|
|
|
|
}, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClientWrapper returns a hystrix client Wrapper.
|
|
|
|
func NewClientWrapper() client.Wrapper {
|
|
|
|
return func(c client.Client) client.Client {
|
|
|
|
return &clientWrapper{c}
|
|
|
|
}
|
|
|
|
}
|