cleanup: main: simplify proxy handling

This commit is contained in:
Markus Linnala 2019-10-09 18:59:46 +03:00 committed by Frank Denis
parent cab67ba5a9
commit 5bf5fe6c1d
3 changed files with 14 additions and 16 deletions

View File

@ -22,7 +22,7 @@ const (
type App struct {
wg sync.WaitGroup
quit chan struct{}
proxy Proxy
proxy *Proxy
}
func main() {
@ -52,7 +52,7 @@ func main() {
}
app.proxy = NewProxy()
_ = ServiceManagerStartNotify()
if err := ConfigLoad(&app.proxy, svcFlag); err != nil {
if err := ConfigLoad(app.proxy, svcFlag); err != nil {
dlog.Fatal(err)
}
if len(*svcFlag) != 0 {
@ -85,29 +85,27 @@ func main() {
}
func (app *App) Start(service service.Service) error {
proxy := &app.proxy
if err := InitPluginsGlobals(&proxy.pluginsGlobals, proxy); err != nil {
if err := app.proxy.InitPluginsGlobals(); err != nil {
dlog.Fatal(err)
}
app.quit = make(chan struct{})
app.wg.Add(1)
if service != nil {
go func() {
app.AppMain(proxy)
app.AppMain()
}()
} else {
app.AppMain(proxy)
app.AppMain()
}
return nil
}
func (app *App) AppMain(proxy *Proxy) {
func (app *App) AppMain() {
pidfile.Write()
proxy.StartProxy()
app.proxy.StartProxy()
<-app.quit
dlog.Notice("Quit signal received...")
app.wg.Done()
}
func (app *App) Stop(service service.Service) error {

View File

@ -82,7 +82,7 @@ type PluginsState struct {
serverName string
}
func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error {
func (proxy *Proxy) InitPluginsGlobals() error {
queryPlugins := &[]Plugin{}
if len(proxy.queryMeta) != 0 {
@ -143,11 +143,11 @@ func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error {
}
}
(*pluginsGlobals).queryPlugins = queryPlugins
(*pluginsGlobals).responsePlugins = responsePlugins
(*pluginsGlobals).loggingPlugins = loggingPlugins
proxy.pluginsGlobals.queryPlugins = queryPlugins
proxy.pluginsGlobals.responsePlugins = responsePlugins
proxy.pluginsGlobals.loggingPlugins = loggingPlugins
parseBlockedQueryResponse(proxy.blockedQueryResponse, pluginsGlobals)
parseBlockedQueryResponse(proxy.blockedQueryResponse, &proxy.pluginsGlobals)
return nil
}

View File

@ -501,8 +501,8 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
}
func NewProxy() Proxy {
return Proxy{
func NewProxy() *Proxy {
return &Proxy{
serversInfo: NewServersInfo(),
}
}