Browse Source

Merge pull request #411 from songzhibin97/gva_gormv2_dev

#409 bug修复
main
奇淼(piexlmax 4 years ago
committed by GitHub
parent
commit
18f2eced02
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      server/model/sys_auto_code.go
  2. 5
      server/service/sys_auto_code.go
  3. 24
      server/utils/file_operations.go

16
server/model/sys_auto_code.go

@ -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 {

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) {
// 去除所有空格
utils.TrimSpace(autoCode)
for _, field := range autoCode.Fields {
utils.TrimSpace(field)
}
// 获取 basePath 文件夹下所有tpl文件
tplFileList, err := GetAllTplFile(basePath, nil)
if err != nil {

24
server/utils/file_operations.go

@ -3,6 +3,8 @@ package utils
import (
"os"
"path/filepath"
"reflect"
"strings"
)
//@author: [songzhibin97](https://github.com/songzhibin97)
@ -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
}
Loading…
Cancel
Save