# hystrix **Repository Path**: colocust/hystrix ## Basic Information - **Project Name**: hystrix - **Description**: Golang熔断器 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-08-27 - **Last Updated**: 2024-02-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 介绍 参考 https://github.com/afex/hystrix-go 开发的熔断器。 ## 快速开始 获取hystrix对象: ```golang h := hystrix.Get() h.ConfigureHystrix("test", &hystrix.Circuit{ Timeout: time.Millisecond * 500, RequestVolumeThreshold: 5, ErrorPercentThreshold: 20, SleepWindow: time.Second * 1, }) ``` 执行代码: ```golang h.Do(context.Background(), "test", func () error { // do something return nil }, func (err error) error { // handle err fmt.Println(err) }) ``` ## 配置 | 配置名 | 解释 | 默认值 | |------------------------|------------------------------------|-----| | Timeout | 函数执行的超时时间,到达设定的阈值,会启用熔断和降级处理 | 1秒 | | RequestVolumeThreshold | 在10s的采样时间内,请求次数打到这个阈值后,才开始判断是否开启熔断 | 20 | | ErrorPercentThreshold | 错误率阈值。超过后,会启用熔断和降级处理。 | 50 | | SleepWindow | 休眠窗口期。熔断后等待试探(是否关闭熔断器)的时间。 | 5秒 |