mirror of
https://github.com/beego/bee.git
synced 2024-11-01 00:00:53 +00:00
added error message if generated file exists
This commit is contained in:
parent
a161ff4755
commit
2f6b7fe0a1
18
g_models.go
18
g_models.go
@ -438,7 +438,11 @@ func writeModelFiles(tables []*Table, mPath string) {
|
|||||||
for _, tb := range tables {
|
for _, tb := range tables {
|
||||||
filename := getFileName(tb.Name)
|
filename := getFileName(tb.Name)
|
||||||
fpath := path.Join(mPath, filename+".go")
|
fpath := path.Join(mPath, filename+".go")
|
||||||
f, _ := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
f, err := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
ColorLog("[ERRO] %v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
template := ""
|
template := ""
|
||||||
if tb.Pk == "" {
|
if tb.Pk == "" {
|
||||||
@ -465,7 +469,11 @@ func writeControllerFiles(tables []*Table, cPath string) {
|
|||||||
}
|
}
|
||||||
filename := getFileName(tb.Name)
|
filename := getFileName(tb.Name)
|
||||||
fpath := path.Join(cPath, filename+".go")
|
fpath := path.Join(cPath, filename+".go")
|
||||||
f, _ := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
f, err := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
ColorLog("[ERRO] %v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
fileStr := strings.Replace(CTRL_TPL, "{{ctrlName}}", camelCase(tb.Name), -1)
|
fileStr := strings.Replace(CTRL_TPL, "{{ctrlName}}", camelCase(tb.Name), -1)
|
||||||
if _, err := f.WriteString(fileStr); err != nil {
|
if _, err := f.WriteString(fileStr); err != nil {
|
||||||
@ -492,7 +500,11 @@ func writeRouterFile(tables []*Table, rPath string) {
|
|||||||
// add export controller
|
// add export controller
|
||||||
fpath := path.Join(rPath, "router.go")
|
fpath := path.Join(rPath, "router.go")
|
||||||
routerStr := strings.Replace(ROUTER_TPL, "{{nameSpaces}}", strings.Join(nameSpaces, ""), 1)
|
routerStr := strings.Replace(ROUTER_TPL, "{{nameSpaces}}", strings.Join(nameSpaces, ""), 1)
|
||||||
f, _ := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
f, err := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
ColorLog("[ERRO] %v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if _, err := f.WriteString(routerStr); err != nil {
|
if _, err := f.WriteString(routerStr); err != nil {
|
||||||
ColorLog("[ERRO] Could not write router file to %s\n", fpath)
|
ColorLog("[ERRO] Could not write router file to %s\n", fpath)
|
||||||
|
Loading…
Reference in New Issue
Block a user