Skip to content

Commit c4f5919

Browse files
committed
fix: 代码生成器 结构体简称发生的关键字冲突 flipped-aurora#1089
1 parent bf1cd15 commit c4f5919

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

server/api/v1/system/sys_auto_code.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
3838
response.FailWithMessage(err.Error(), c)
3939
return
4040
}
41-
41+
a.KeyWord() // 处理go关键字
4242
a.PackageT = caser.String(a.Package)
4343
autoCode, err := autoCodeService.PreviewTemp(a)
4444
if err != nil {
@@ -65,6 +65,7 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
6565
response.FailWithMessage(err.Error(), c)
6666
return
6767
}
68+
a.KeyWord() // 处理go关键字
6869
var apiIds []uint
6970
if a.AutoCreateApiToSql {
7071
if ids, err := autoCodeService.AutoCreateApi(&a); err != nil {

server/model/system/sys_auto_code.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package system
33
import (
44
"errors"
55
"github.com/flipped-aurora/gin-vue-admin/server/global"
6+
"go/token"
67
)
78

89
// AutoCodeStruct 初始版本自动化代码工具
@@ -21,6 +22,14 @@ type AutoCodeStruct struct {
2122
PackageT string `json:"-"`
2223
}
2324

25+
// KeyWord 是go关键字的处理加上 _ ,防止编译报错
26+
// Author [SliverHorn](https://github.com/SliverHorn)
27+
func (a *AutoCodeStruct) KeyWord() {
28+
if token.IsKeyword(a.Abbreviation) {
29+
a.Abbreviation = "_" + a.Abbreviation
30+
}
31+
}
32+
2433
type Field struct {
2534
FieldName string `json:"fieldName"` // Field名
2635
FieldDesc string `json:"fieldDesc"` // 中文名

0 commit comments

Comments
 (0)