diff --git a/generator/main.go b/generator/main.go index bef23656..61aa61fb 100644 --- a/generator/main.go +++ b/generator/main.go @@ -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") } + } }