mirror of
https://github.com/simon987/Architeuthis.git
synced 2025-12-15 01:49:02 +00:00
Add hot config reload
This commit is contained in:
27
config.go
27
config.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -98,6 +99,32 @@ func applyConfig(proxy *Proxy) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Balancer) reloadConfig() {
|
||||
|
||||
b.proxyMutex.Lock()
|
||||
loadConfig()
|
||||
|
||||
if b.proxies != nil {
|
||||
b.proxies = b.proxies[:0]
|
||||
}
|
||||
|
||||
for _, proxyConf := range config.Proxies {
|
||||
proxy, err := NewProxy(proxyConf.Name, proxyConf.Url)
|
||||
handleErr(err)
|
||||
b.proxies = append(b.proxies, proxy)
|
||||
|
||||
applyConfig(proxy)
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"name": proxy.Name,
|
||||
"url": proxy.Url,
|
||||
}).Info("Proxy")
|
||||
}
|
||||
b.proxyMutex.Unlock()
|
||||
|
||||
logrus.Info("Reloaded config")
|
||||
}
|
||||
|
||||
func handleErr(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user