From 943bd6a3ae336d6b6847b172b9814ec02fd73d7c Mon Sep 17 00:00:00 2001 From: tianwen Date: Tue, 29 Mar 2022 16:27:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=90=8E=E6=9C=AA=E5=85=B3=E9=97=AD=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/app.go b/app/app.go index a73606b..f7eb27e 100644 --- a/app/app.go +++ b/app/app.go @@ -110,7 +110,7 @@ func newOptions(opts ...module.Option) module.Options { } ApplicationDir := "" if opt.WorkDir != "" { - _, err := os.Open(opt.WorkDir) + _, err := os.Stat(opt.WorkDir) if err != nil { panic(err) } @@ -155,28 +155,25 @@ func newOptions(opts ...module.Option) module.Options { } } - _, err := os.Open(opt.ConfPath) - if err != nil { + if _, err := os.Stat(opt.ConfPath); err != nil { //文件不存在 panic(fmt.Sprintf("config path error %v", err)) } - _, err = os.Open(opt.LogDir) - if err != nil { + if _, err := os.Stat(opt.LogDir); err != nil { //文件不存在 - err := os.Mkdir(opt.LogDir, os.ModePerm) // + err := os.Mkdir(opt.LogDir, os.ModePerm) if err != nil { fmt.Println(err) } } - - _, err = os.Open(opt.BIDir) - if err != nil { + if _, err := os.Stat(opt.BIDir); err != nil { //文件不存在 - err := os.Mkdir(opt.BIDir, os.ModePerm) // + err := os.Mkdir(opt.BIDir, os.ModePerm) if err != nil { fmt.Println(err) } } + return opt } @@ -209,14 +206,13 @@ type DefaultApp struct { // Run 运行应用 func (app *DefaultApp) Run(mods ...module.Module) error { - f, err := os.Open(app.opts.ConfPath) - if err != nil { + if _, err := os.Stat(app.opts.ConfPath); err != nil { //文件不存在 panic(fmt.Sprintf("config path error %v", err)) } var cof conf.Config fmt.Println("Server configuration path :", app.opts.ConfPath) - conf.LoadConfig(f.Name()) //加载配置文件 + conf.LoadConfig(app.opts.ConfPath) //加载配置文件 cof = conf.Conf app.Configure(cof) //解析配置信息