Skip to content

Commit adea923

Browse files
committed
feat:filter_test_suffix
1 parent 0076c7c commit adea923

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

server/api/v1/system/sys_auto_code.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
3737
response.FailWithMessage(err.Error(), c)
3838
return
3939
}
40-
a.KeyWord() // 处理go关键字
40+
a.Pretreatment() // 处理go关键字
4141
a.PackageT = caser.String(a.Package)
4242
autoCode, err := autoCodeService.PreviewTemp(a)
4343
if err != nil {
@@ -64,7 +64,7 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
6464
response.FailWithMessage(err.Error(), c)
6565
return
6666
}
67-
a.KeyWord() // 处理go关键字
67+
a.Pretreatment()
6868
var apiIds []uint
6969
if a.AutoCreateApiToSql {
7070
if ids, err := autoCodeService.AutoCreateApi(&a); err != nil {

server/model/system/sys_auto_code.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"github.com/flipped-aurora/gin-vue-admin/server/global"
66
"go/token"
7+
"strings"
78
)
89

910
// AutoCodeStruct 初始版本自动化代码工具
@@ -23,6 +24,11 @@ type AutoCodeStruct struct {
2324
PackageT string `json:"-"`
2425
}
2526

27+
func (a *AutoCodeStruct) Pretreatment() {
28+
a.KeyWord()
29+
a.SuffixTest()
30+
}
31+
2632
// KeyWord 是go关键字的处理加上 _ ,防止编译报错
2733
// Author [SliverHorn](https://github.com/SliverHorn)
2834
func (a *AutoCodeStruct) KeyWord() {
@@ -31,6 +37,14 @@ func (a *AutoCodeStruct) KeyWord() {
3137
}
3238
}
3339

40+
// SuffixTest 处理_test 后缀
41+
// Author [SliverHorn](https://github.com/SliverHorn)
42+
func (a *AutoCodeStruct) SuffixTest() {
43+
if strings.HasSuffix(a.Package, "test") {
44+
a.Package = a.Package + "_"
45+
}
46+
}
47+
3448
type Field struct {
3549
FieldName string `json:"fieldName"` // Field名
3650
FieldDesc string `json:"fieldDesc"` // 中文名

0 commit comments

Comments
 (0)