1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-28 00:20:13 +01:00

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

View File

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