circuitbreaker

package
v0.0.0-...-30b4b00 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowRequest

func AllowRequest(channelId int64) bool

AllowRequest 检查指定渠道的断路器是否允许请求 供 middleware/distributor.go 在选择渠道前调用

func InitManager

func InitManager(failureThreshold, successThreshold int, timeout time.Duration)

InitManager 初始化全局断路器管理器(应在 main.go 中调用)

func RecordFailure

func RecordFailure(channelId int64)

RecordFailure 记录指定渠道的失败请求 供 controller/relay.go 在请求失败后调用

func RecordSuccess

func RecordSuccess(channelId int64)

RecordSuccess 记录指定渠道的成功请求 供 controller/relay.go 在请求成功后调用

func RemoveChannel

func RemoveChannel(channelId int64)

RemoveChannel 移除指定渠道的断路器

func ResetChannel

func ResetChannel(channelId int64)

ResetChannel 重置指定渠道的断路器

Types

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker 单个渠道的断路器

func New

func New(failureThreshold, successThreshold int, timeout time.Duration) *CircuitBreaker

New 创建新的断路器实例

func (*CircuitBreaker) AllowRequest

func (cb *CircuitBreaker) AllowRequest() bool

AllowRequest 判断是否允许请求通过

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() State

GetState 获取当前状态

func (*CircuitBreaker) RecordFailure

func (cb *CircuitBreaker) RecordFailure()

RecordFailure 记录失败请求

func (*CircuitBreaker) RecordSuccess

func (cb *CircuitBreaker) RecordSuccess()

RecordSuccess 记录成功请求

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset 重置断路器到初始状态

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理所有渠道的断路器实例 线程安全,懒初始化

func GetManager

func GetManager() *Manager

GetManager 获取全局断路器管理器

func (*Manager) Get

func (m *Manager) Get(channelId int64) *CircuitBreaker

Get 获取指定渠道的断路器(懒初始化)

func (*Manager) GetAllStates

func (m *Manager) GetAllStates() map[int64]string

GetAllStates 获取所有断路器的状态(用于 API 查询 / 调试)

func (*Manager) Remove

func (m *Manager) Remove(channelId int64)

Remove 移除指定渠道的断路器(渠道被删除时调用)

func (*Manager) Reset

func (m *Manager) Reset(channelId int64)

Reset 重置指定渠道的断路器(关闭 → 初始状态)

func (*Manager) ResetAll

func (m *Manager) ResetAll()

ResetAll 重置所有断路器

type State

type State int

State 断路器状态

const (
	StateClosed   State = iota // 关闭态:正常放行请求
	StateOpen                  // 断开态:快速失败,不转发请求
	StateHalfOpen              // 半开态:放行一个探测请求
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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