lolly/internal/loadbalance/algorithms.go
xfy 92cd93d4c0 refactor: 代码改进与注释补充
- logging: 补充包文档说明
- pool: 修复 workers 计数器并发安全 (atomic 操作)
- stream: 完善注释与错误处理
- handler/static: 添加预压缩文件支持接口
- loadbalance: 补充算法注释
- vhost: 改进虚拟主机路由逻辑
- ssl: 优化证书加载注释
- main: 补充启动流程注释

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:57:59 +08:00

38 lines
914 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
// 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
}
for _, a := range ValidAlgorithms {
if a == alg {
return true
}
}
return false
}