2021-01-29 19:31:11 -05:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
sync "sync"
|
|
|
|
)
|
|
|
|
|
2021-06-18 19:02:46 -04:00
|
|
|
func (r *Router) OverrideBalancer(balancer string, target string) error {
|
2021-01-29 19:31:11 -05:00
|
|
|
var b *Balancer
|
|
|
|
for tag, bl := range r.balancers {
|
|
|
|
if tag == balancer {
|
|
|
|
b = bl
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if b == nil {
|
|
|
|
return newError("balancer '", balancer, "' not found")
|
|
|
|
}
|
2021-06-18 19:02:46 -04:00
|
|
|
b.override.Put(target)
|
2021-01-29 19:31:11 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
type overrideSettings struct {
|
2021-06-18 19:02:46 -04:00
|
|
|
target string
|
2021-01-29 19:31:11 -05:00
|
|
|
}
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
type override struct {
|
2021-01-29 19:31:11 -05:00
|
|
|
access sync.RWMutex
|
2021-02-21 10:02:42 -05:00
|
|
|
settings overrideSettings
|
2021-01-29 19:31:11 -05:00
|
|
|
}
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
// Get gets the override settings
|
2021-06-18 19:02:46 -04:00
|
|
|
func (o *override) Get() string {
|
2021-01-29 19:31:11 -05:00
|
|
|
o.access.RLock()
|
|
|
|
defer o.access.RUnlock()
|
2021-06-18 19:02:46 -04:00
|
|
|
return o.settings.target
|
2021-01-29 19:31:11 -05:00
|
|
|
}
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
// Put updates the override settings
|
2021-06-18 19:02:46 -04:00
|
|
|
func (o *override) Put(target string) {
|
2021-01-29 19:31:11 -05:00
|
|
|
o.access.Lock()
|
|
|
|
defer o.access.Unlock()
|
2021-06-18 19:02:46 -04:00
|
|
|
o.settings.target = target
|
2021-01-29 19:31:11 -05:00
|
|
|
}
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
// Clear clears the override settings
|
|
|
|
func (o *override) Clear() {
|
2021-01-29 19:31:11 -05:00
|
|
|
o.access.Lock()
|
|
|
|
defer o.access.Unlock()
|
2021-06-18 19:02:46 -04:00
|
|
|
o.settings.target = ""
|
2021-01-29 19:31:11 -05:00
|
|
|
}
|