Documentation
¶
Index ¶
- type FallbackFunc
- type FallbackFuncC
- type Fuse
- type Hystrix
- func (h *Hystrix) ConfigureCommand(name string, config hystrix.CommandConfig)
- func (h *Hystrix) Do(name string, run RunFunc, fallback FallbackFunc) error
- func (h *Hystrix) DoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) error
- func (h *Hystrix) Go(name string, run RunFunc, fallback FallbackFunc) chan error
- func (h *Hystrix) GoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) chan error
- type RunFunc
- type RunFuncC
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FallbackFunc ¶
type Fuse ¶
type Fuse interface {
// Do 以同步的方式运行 RunFunc,直到成功为止
// 如果返回错误,执行 FallbackFunc 函数
Do(name string, run RunFunc, fallback FallbackFunc) error
// DoC 同步方式处理
DoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) error
// Go 异步调用返回 channel
Go(name string, run RunFunc, fallback FallbackFunc) chan error
// GoC
// Do/Go 都调用GoC, Do中处理了异步过程
GoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) chan error
// ConfigureCommand 配置参数
ConfigureCommand(name string, config hystrix.CommandConfig)
}
Fuse 熔断降级接口
type Hystrix ¶
type Hystrix struct{}
func (*Hystrix) ConfigureCommand ¶
func (h *Hystrix) ConfigureCommand(name string, config hystrix.CommandConfig)
Example ¶
// 不设置 ConfigureCommand 走默认配置
// hystrix.CommandConfig{} 设置参数
fuse.ConfigureCommand("test", hystrix.CommandConfig{})
func (*Hystrix) Do ¶
func (h *Hystrix) Do(name string, run RunFunc, fallback FallbackFunc) error
Example ¶
// Do: 同步执行 func() error, 没有超时控制 直到等到返回,
// 如果返回 error != nil 则触发 FallbackFunc 进行降级
err := fuse.Do("do", mockRunFunc(), mockFallbackFunc())
if err != nil {
// 处理 error
}
Click to show internal directories.
Click to hide internal directories.