Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.go 处理文件的相关问题 #132

Open
sandy1219 opened this issue Jul 8, 2022 · 0 comments
Open

app.go 处理文件的相关问题 #132

sandy1219 opened this issue Jul 8, 2022 · 0 comments

Comments

@sandy1219
Copy link

1:newOptions函数里边

_, err := os.Open(opt.ConfPath)
if err != nil {
//文件不存在
panic(fmt.Sprintf("config path error %v", err))
}
_, err = os.Open(opt.LogDir)
if err != nil {
//文件不存在
err := os.Mkdir(opt.LogDir, os.ModePerm) //
if err != nil {
fmt.Println(err)
}
}

_, err = os.Open(opt.BIDir)
if err != nil {
	//文件不存在
	err := os.Mkdir(opt.BIDir, os.ModePerm) //
	if err != nil {
		fmt.Println(err)
	}
}

是不是改成下边这段代码更合适
if _, err := os.Stat(opt.ConfPath); os.IsNotExist(err) {
panic(fmt.Sprintf("config path error %v", err))
}
if _,err := os.Stat(opt.LogDir);os.IsNotExist(err){
if err := os.Mkdir(opt.LogDir, os.ModePerm);err != nil{
fmt.Println(err)
}
}
if _,err := os.Stat(opt.BIDir);os.IsNotExist(err){
if err := os.Mkdir(opt.BIDir, os.ModePerm);err != nil{
fmt.Println(err)
}
}

2:Run 里边
f, err := os.Open(app.opts.ConfPath)
if err != nil {
//文件不存在
panic(fmt.Sprintf("config path error %v", err))
}
这一步检测 个人觉得可以去掉,Run之前 newOptions()里边已经检测过ConfigPath,直接去掉 然后
conf.LoadConfig(app.opts.ConfPath)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant