...
1 package circuitbreaker
2
3 import (
4 "context"
5
6 "github.com/afex/hystrix-go/hystrix"
7
8 "github.com/go-kit/kit/endpoint"
9 )
10
11
12
13
14
15
16
17
18 func Hystrix(commandName string) endpoint.Middleware {
19 return func(next endpoint.Endpoint) endpoint.Endpoint {
20 return func(ctx context.Context, request interface{}) (response interface{}, err error) {
21 var resp interface{}
22 if err := hystrix.Do(commandName, func() (err error) {
23 resp, err = next(ctx, request)
24 return err
25 }, nil); err != nil {
26 return nil, err
27 }
28 return resp, nil
29 }
30 }
31 }
32
View as plain text