- logging: 补充包文档说明 - pool: 修复 workers 计数器并发安全 (atomic 操作) - stream: 完善注释与错误处理 - handler/static: 添加预压缩文件支持接口 - loadbalance: 补充算法注释 - vhost: 改进虚拟主机路由逻辑 - ssl: 优化证书加载注释 - main: 补充启动流程注释 Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
914 B
Go
38 lines
914 B
Go
// 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
|
||
}
|