mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-05 12:39:21 +02:00
51 lines
882 B
Go
51 lines
882 B
Go
|
package router
|
||
|
|
||
|
import (
|
||
|
sync "sync"
|
||
|
)
|
||
|
|
||
|
func (r *Router) OverrideBalancer(balancer string, target string) error {
|
||
|
var b *Balancer
|
||
|
for tag, bl := range r.balancers {
|
||
|
if tag == balancer {
|
||
|
b = bl
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if b == nil {
|
||
|
return newError("balancer '", balancer, "' not found")
|
||
|
}
|
||
|
b.override.Put(target)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type overrideSettings struct {
|
||
|
target string
|
||
|
}
|
||
|
|
||
|
type override struct {
|
||
|
access sync.RWMutex
|
||
|
settings overrideSettings
|
||
|
}
|
||
|
|
||
|
// Get gets the override settings
|
||
|
func (o *override) Get() string {
|
||
|
o.access.RLock()
|
||
|
defer o.access.RUnlock()
|
||
|
return o.settings.target
|
||
|
}
|
||
|
|
||
|
// Put updates the override settings
|
||
|
func (o *override) Put(target string) {
|
||
|
o.access.Lock()
|
||
|
defer o.access.Unlock()
|
||
|
o.settings.target = target
|
||
|
}
|
||
|
|
||
|
// Clear clears the override settings
|
||
|
func (o *override) Clear() {
|
||
|
o.access.Lock()
|
||
|
defer o.access.Unlock()
|
||
|
o.settings.target = ""
|
||
|
}
|