Skip to content

Commit

Permalink
flipped-aurora#409 bug修复
Browse files Browse the repository at this point in the history
- 修改
server/model/sys_auto_code.go
server/service/sys_auto_code.go
server/utils/file_operations.go
  • Loading branch information
songzhibin97 committed Mar 24, 2021
1 parent 0d65d25 commit cb1eacc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/model/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "errors"

// 初始版本自动化代码工具
type AutoCodeStruct struct {
StructName string `json:"structName"`
TableName string `json:"tableName"`
PackageName string `json:"packageName"`
Abbreviation string `json:"abbreviation"`
Description string `json:"description"`
AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
AutoMoveFile bool `json:"autoMoveFile"`
Fields []Field `json:"fields"`
StructName string `json:"structName"`
TableName string `json:"tableName"`
PackageName string `json:"packageName"`
Abbreviation string `json:"abbreviation"`
Description string `json:"description"`
AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
AutoMoveFile bool `json:"autoMoveFile"`
Fields []*Field `json:"fields"`
}

type Field struct {
Expand Down
5 changes: 5 additions & 0 deletions server/service/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ func AutoCreateApi(a *model.AutoCodeStruct) (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文件
tplFileList, err := GetAllTplFile(basePath, nil)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions server/utils/file_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package utils
import (
"os"
"path/filepath"
"reflect"
"strings"
)

//@author: [songzhibin97](https://github.com/songzhibin97)
Expand Down Expand Up @@ -39,3 +41,25 @@ Redirect:
}
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
}

0 comments on commit cb1eacc

Please sign in to comment.