mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:58:45 +02:00
added round_robin, least_conn and ip_hash load balance support, small refactoring
This commit is contained in:
29
internal/net/http/loadbalancer/mode.go
Normal file
29
internal/net/http/loadbalancer/mode.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package loadbalancer
|
||||
|
||||
import (
|
||||
U "github.com/yusing/go-proxy/internal/utils"
|
||||
)
|
||||
|
||||
type Mode string
|
||||
|
||||
const (
|
||||
RoundRobin Mode = "roundrobin"
|
||||
LeastConn Mode = "leastconn"
|
||||
IPHash Mode = "iphash"
|
||||
)
|
||||
|
||||
func (mode *Mode) ValidateUpdate() bool {
|
||||
switch U.ToLowerNoSnake(string(*mode)) {
|
||||
case "", string(RoundRobin):
|
||||
*mode = RoundRobin
|
||||
return true
|
||||
case string(LeastConn):
|
||||
*mode = LeastConn
|
||||
return true
|
||||
case string(IPHash):
|
||||
*mode = IPHash
|
||||
return true
|
||||
}
|
||||
*mode = RoundRobin
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user