move ConfigLoad into AppMain

This commit is contained in:
Alison Winters 2019-10-30 21:34:00 +08:00 committed by Frank Denis
parent 2f7e057996
commit 816acb9d8d
1 changed files with 12 additions and 9 deletions

View File

@ -23,6 +23,7 @@ type App struct {
wg sync.WaitGroup
quit chan struct{}
proxy *Proxy
flags *ConfigFlags
}
func main() {
@ -67,7 +68,9 @@ func main() {
os.Exit(0)
}
app := &App{}
app := &App{
flags: &flags,
}
svc, err := service.New(app, svcConfig)
if err != nil {
svc = nil
@ -75,9 +78,6 @@ func main() {
}
app.proxy = NewProxy()
_ = ServiceManagerStartNotify()
if err := ConfigLoad(app.proxy, &flags); err != nil {
dlog.Fatal(err)
}
if len(*svcFlag) != 0 {
if svc == nil {
dlog.Fatal("Built-in service installation is not supported on this platform")
@ -108,11 +108,6 @@ func main() {
}
func (app *App) Start(service service.Service) error {
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()
@ -124,6 +119,14 @@ func (app *App) Start(service service.Service) error {
}
func (app *App) AppMain() {
if err := ConfigLoad(app.proxy, app.flags); err != nil {
dlog.Fatal(err)
}
if err := app.proxy.InitPluginsGlobals(); err != nil {
dlog.Fatal(err)
}
app.quit = make(chan struct{})
app.wg.Add(1)
pidfile.Write()
app.proxy.StartProxy()
<-app.quit