Browse Source

#409 bug修复

- 修改
server/model/sys_auto_code.go
server/service/sys_auto_code.go
server/utils/file_operations.go
main
songzhibin97 4 years ago
parent
commit
cb1eaccfaf
  1. 2
      server/model/sys_auto_code.go
  2. 5
      server/service/sys_auto_code.go
  3. 24
      server/utils/file_operations.go

2
server/model/sys_auto_code.go

@ -11,7 +11,7 @@ type AutoCodeStruct struct {
Description string `json:"description"` Description string `json:"description"`
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
AutoMoveFile bool `json:"autoMoveFile"` AutoMoveFile bool `json:"autoMoveFile"`
Fields []Field `json:"fields"`
Fields []*Field `json:"fields"`
} }
type Field struct { type Field struct {

5
server/service/sys_auto_code.go

@ -320,6 +320,11 @@ func AutoCreateApi(a *model.AutoCodeStruct) (err error) {
} }
func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) { func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) {
// 去除所有空格
utils.TrimSpace(autoCode)
for _, field := range autoCode.Fields {
utils.TrimSpace(field)
}
// 获取 basePath 文件夹下所有tpl文件 // 获取 basePath 文件夹下所有tpl文件
tplFileList, err := GetAllTplFile(basePath, nil) tplFileList, err := GetAllTplFile(basePath, nil)
if err != nil { if err != nil {

24
server/utils/file_operations.go

@ -3,6 +3,8 @@ package utils
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"strings"
) )
//@author: [songzhibin97](https://github.com/songzhibin97) //@author: [songzhibin97](https://github.com/songzhibin97)
@ -39,3 +41,25 @@ Redirect:
} }
return os.Rename(src, dst) return os.Rename(src, dst)
} }
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: TrimSpace
//@description: 去除结构体空格
//@param: target interface (target: 目标结构体,传入必须是指针类型)
//@return: err error
func TrimSpace(target interface{}) {
t := reflect.TypeOf(target)
if t.Kind() != reflect.Ptr {
return
}
t = t.Elem()
v := reflect.ValueOf(target).Elem()
for i := 0; i < t.NumField(); i++ {
switch v.Field(i).Kind() {
case reflect.String:
v.Field(i).SetString(strings.TrimSpace(v.Field(i).String()))
}
}
return
}
Loading…
Cancel
Save