修复一个logic代码不覆盖的逻辑

This commit is contained in:
eson 2023-06-15 16:17:42 +08:00
parent 66c043534f
commit dfc411b9c6

View File

@ -142,16 +142,26 @@ func GenFromPath(pth string) {
}
fcontent = "package model\n// TODO: 使用model的属性做你想做的"
genGoFileName = fmt.Sprintf("%s/%s_logic.go", genDir, table.Name)
f2, err := os.OpenFile(genGoFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
f2.WriteString(fcontent)
err = f2.Close()
if err != nil {
panic(err)
genGoLogicFileName := fmt.Sprintf("%s/%s_logic.go", genDir, table.Name)
// 使用 os.Stat 函数获取文件信息
_, err = os.Stat(genGoLogicFileName)
// 判断文件是否存在并输出结果
if os.IsNotExist(err) {
f2, err := os.OpenFile(genGoLogicFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
f2.WriteString(fcontent)
err = f2.Close()
if err != nil {
panic(err)
}
fmt.Println(genGoLogicFileName, "create!")
} else {
fmt.Println(genGoLogicFileName, "exists")
}
}
}