lolly/internal/loadbalance/algorithms.go
xfy 95b6119e34 refactor: 使用标准库 slices/maps 替代自定义函数
- 使用 slices.Contains 替代 contains/containsInt 函数
- 使用 maps.Copy 替代手动遍历复制
- 删除 internal/cache 中不再需要的辅助函数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:13 +08:00

35 lines
888 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package loadbalance 负载均衡包,提供多种负载均衡算法实现。
//
// 该文件包含负载均衡相关的核心逻辑,包括:
// - 轮询算法Round Robin
// - 加权轮询算法Weighted Round Robin
// - 最少连接算法Least Connections
// - IP 哈希算法IP Hash
// - 一致性哈希算法Consistent Hash
//
// 主要用途:
//
// 用于在后端服务器之间分发请求,提高服务可用性和性能。
//
// 作者xfy
package loadbalance
import "slices"
// ValidAlgorithms 是支持的负载均衡算法列表。
var ValidAlgorithms = []string{
"round_robin",
"weighted_round_robin",
"least_conn",
"ip_hash",
"consistent_hash",
}
// IsValidAlgorithm 检查算法是否有效。
func IsValidAlgorithm(alg string) bool {
if alg == "" {
return true
}
return slices.Contains(ValidAlgorithms, alg)
}