refactor file|path (#1409)

Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
anqiansong
2022-01-03 21:32:40 +08:00
committed by GitHub
parent 290de6aa96
commit 89ce5e492b
81 changed files with 279 additions and 245 deletions

View File

@@ -10,19 +10,19 @@ import (
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
"github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
)
// MaybeCreateFile creates file if not exists
func MaybeCreateFile(dir, subdir, file string) (fp *os.File, created bool, err error) {
logx.Must(util.MkdirIfNotExist(path.Join(dir, subdir)))
logx.Must(pathx.MkdirIfNotExist(path.Join(dir, subdir)))
fpath := path.Join(dir, subdir, file)
if util.FileExists(fpath) {
if pathx.FileExists(fpath) {
fmt.Printf("%s exists, ignored generation\n", fpath)
return nil, false, nil
}
fp, err = util.CreateIfNotExist(fpath)
fp, err = pathx.CreateIfNotExist(fpath)
created = err == nil
return
}