Xray-core/app/router/balancing_override.go
yuhan6665 079d0bd8a9
Refactor log (#3446)
* Refactor log

* Add new log methods

* Fix logger test

* Change all logging code

* Clean up pathObj

* Rebase to latest main

* Remove invoking method name after the dot
2024-06-29 14:32:57 -04:00

52 lines
928 B
Go

package router
import (
sync "sync"
"github.com/xtls/xray-core/common/errors"
)
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 errors.New("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 = ""
}