- server: 集成反向代理路由,支持单服务器和虚拟主机两种模式 - loadbalance: 使用 atomic.Bool 替代 bool 实现并发安全的健康状态 - proxy: 适配 atomic.Bool,移除 HealthChecker 不必要的互斥锁 - config: 添加服务器超时配置字段,验证负载均衡算法 - 新增 algorithms.go 提供算法验证函数 - 新增 config.example.yaml 配置示例文件 Co-Authored-By: Claude <noreply@anthropic.com>
24 lines
486 B
Go
24 lines
486 B
Go
// Package loadbalance 负载均衡包为 Lolly HTTP 服务器提供负载均衡算法。
|
|
package loadbalance
|
|
|
|
// ValidAlgorithms 是支持的负载均衡算法列表。
|
|
var ValidAlgorithms = []string{
|
|
"round_robin",
|
|
"weighted_round_robin",
|
|
"least_conn",
|
|
"ip_hash",
|
|
}
|
|
|
|
// IsValidAlgorithm 检查算法是否有效。
|
|
func IsValidAlgorithm(alg string) bool {
|
|
if alg == "" {
|
|
return true
|
|
}
|
|
for _, a := range ValidAlgorithms {
|
|
if a == alg {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|