downgrade

package
v1.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackFunc added in v1.1.7

type FallbackFunc = func(error) error

type FallbackFuncC added in v1.1.7

type FallbackFuncC = func(context.Context, error) error

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 熔断降级接口

func NewFuse

func NewFuse() Fuse

NewFuse 实例化方法

Example
// 拿到一个熔断器
fuse = NewFuse()
Output:

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{})
Output:

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
}
Output:

func (*Hystrix) DoC added in v1.1.8

func (h *Hystrix) DoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) error

func (*Hystrix) Go

func (h *Hystrix) Go(name string, run RunFunc, fallback FallbackFunc) chan error
Example
// Go: 异步执行 返回 channel
ch := fuse.Go("go", mockRunFunc(), mockFallbackFunc())
if err := <-ch; err != nil {
	// 处理 error
}
Output:

func (*Hystrix) GoC

func (h *Hystrix) GoC(ctx context.Context, name string, run RunFuncC, fallback FallbackFuncC) chan error
Example
// GoC: Do/Go 实际上最终调用的就是GoC, Do主处理了异步过程
// GoC可以传入 context 保证链路超时控制
fuse.GoC(context.TODO(), "goc", mockRunFuncC(), mockFallbackFuncC())
Output:

type RunFunc added in v1.1.7

type RunFunc = func() error

type RunFuncC added in v1.1.7

type RunFuncC = func(context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL