Support hot update config

This commit is contained in:
DullJZ
2025-09-24 21:15:11 +08:00
parent 4b5c9a658d
commit c92b874bba
6 changed files with 435 additions and 6 deletions
+7 -2
View File
@@ -87,7 +87,7 @@ func (b *Balancer) GetStrategy() string {
// 允许在运行时更改负载均衡策略
func (b *Balancer) SetStrategy(strategyName string) error {
var strategy Strategy
switch strategyName {
case "round-robin":
strategy = NewRoundRobinStrategy()
@@ -100,11 +100,16 @@ func (b *Balancer) SetStrategy(strategyName string) error {
default:
return fmt.Errorf("unknown balancer strategy: %s", strategyName)
}
b.strategy = strategy
return nil
}
// UpdateStrategy 更新负载均衡策略(热更新用)
func (b *Balancer) UpdateStrategy(strategyName string) error {
return b.SetStrategy(strategyName)
}
// SetMetrics 设置指标服务
func (b *Balancer) SetMetrics(metrics *metrics.Metrics) {
b.metrics = metrics