Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
eda1ac10
Z
zendata
项目概览
易企天创
/
zendata
9 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eda1ac10
编写于
12月 15, 2022
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactoring data generation codes
上级
1c4a5630
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
219 addition
and
52 deletion
+219
-52
demo/t.yaml
demo/t.yaml
+3
-3
internal/pkg/ctrl/field.go
internal/pkg/ctrl/field.go
+7
-8
internal/pkg/gen/helper/comm.go
internal/pkg/gen/helper/comm.go
+1
-1
internal/pkg/gen/list.go
internal/pkg/gen/list.go
+4
-4
internal/pkg/gen/printer.go
internal/pkg/gen/printer.go
+1
-1
internal/pkg/service/combine.go
internal/pkg/service/combine.go
+4
-3
internal/pkg/service/field.go
internal/pkg/service/field.go
+2
-9
internal/pkg/service/list.go
internal/pkg/service/list.go
+29
-0
internal/pkg/service/output-json.go
internal/pkg/service/output-json.go
+8
-4
internal/pkg/service/output-rows.go
internal/pkg/service/output-rows.go
+3
-1
internal/pkg/service/placeholder.go
internal/pkg/service/placeholder.go
+134
-0
internal/pkg/service/range.go
internal/pkg/service/range.go
+8
-7
pkg/utils/vari/var.go
pkg/utils/vari/var.go
+15
-11
未找到文件。
demo/t.yaml
浏览文件 @
eda1ac10
...
...
@@ -4,7 +4,7 @@ version: 1.0
fields
:
-
field
:
f1
range
:
0-9
range
:
0-9
:R
loop
:
1-3
prefix
:
a-c
postfix
:
"
\t
"
...
...
@@ -13,7 +13,7 @@ fields:
postfix
:
"
\t
"
-
field
:
union_false
#
mode: r
mode
:
r
postfix
:
"
\t
"
fields
:
-
field
:
child1
...
...
@@ -26,7 +26,7 @@ fields:
prefix
:
part2_
-
field
:
union_true
# mode: r
mode
:
p
union
:
true
fields
:
-
field
:
child1
...
...
internal/pkg/ctrl/field.go
浏览文件 @
eda1ac10
...
...
@@ -2,20 +2,19 @@ package ctrl
import
(
constant
"github.com/easysoft/zendata/internal/pkg/const"
"github.com/easysoft/zendata/internal/pkg/gen"
"github.com/easysoft/zendata/internal/pkg/model"
"github.com/easysoft/zendata/internal/pkg/service"
)
type
FieldCtrl
struct
{
Field
*
model
.
DefField
FieldService
*
service
.
FieldService
ValueService
*
service
.
ValueService
Field
*
model
.
DefField
FieldService
*
service
.
FieldService
ValueService
*
service
.
ValueService
ListService
*
service
.
ListService
`inject:""`
ArticleService
*
service
.
ArticleService
`inject:""`
}
func
(
c
*
FieldCtrl
)
CreateField
()
{
fieldWithValue
:=
model
.
FieldWithValues
{}
if
c
.
Field
.
Type
==
""
{
// set default
c
.
Field
.
Type
=
constant
.
FieldTypeList
}
...
...
@@ -27,9 +26,9 @@ func (c *FieldCtrl) CreateField() {
}
if
c
.
Field
.
Type
==
constant
.
FieldTypeList
{
gen
.
CreateListField
(
c
.
Field
,
&
fieldWithValue
)
c
.
ListService
.
CreateListField
(
c
.
Field
)
}
else
if
c
.
Field
.
Type
==
constant
.
FieldTypeArticle
{
gen
.
CreateArticleField
(
c
.
Field
,
&
fieldWithValue
)
c
.
ArticleService
.
CreateArticleField
(
c
.
Field
)
}
else
if
c
.
Field
.
Type
==
constant
.
FieldTypeTimestamp
{
c
.
ValueService
.
CreateTimestampField
(
c
.
Field
)
}
else
if
c
.
Field
.
Type
==
constant
.
FieldTypeUlid
{
...
...
internal/pkg/gen/helper/comm.go
浏览文件 @
eda1ac10
...
...
@@ -7,7 +7,7 @@ import (
func
GetRandFieldSection
(
pth
string
)
(
key
int
)
{
max
:=
0
for
k
,
v
:=
range
vari
.
RandFieldSectionShortKeysToPathMap
{
for
k
,
v
:=
range
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
{
if
pth
==
v
{
key
=
k
return
...
...
internal/pkg/gen/list.go
浏览文件 @
eda1ac10
...
...
@@ -235,8 +235,8 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
mp
:=
PlaceholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
field
.
Format
,
repeat
,
repeatTag
)
vari
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
return
}
...
...
@@ -301,8 +301,8 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
mp
:=
PlaceholderMapForRandValues
(
dataType
,
strItems
,
startStr
,
endStr
,
fmt
.
Sprintf
(
"%v"
,
step
),
strconv
.
Itoa
(
precision
),
field
.
Format
,
repeat
,
repeatTag
)
vari
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
return
}
...
...
internal/pkg/gen/printer.go
浏览文件 @
eda1ac10
...
...
@@ -238,7 +238,7 @@ func replacePlaceholder(col string) string {
func
getValForPlaceholder
(
placeholderStr
string
,
count
int
)
[]
string
{
placeholderInt
,
_
:=
strconv
.
Atoi
(
placeholderStr
)
mp
:=
vari
.
RandFieldSectionPathToValuesMap
[
placeholderInt
]
mp
:=
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
placeholderInt
]
tp
:=
mp
[
"type"
]
.
(
string
)
repeatObj
:=
mp
[
"repeat"
]
...
...
internal/pkg/service/combine.go
浏览文件 @
eda1ac10
...
...
@@ -8,9 +8,10 @@ import (
)
type
CombineService
struct
{
ExpressionService
*
ExpressionService
`inject:""`
LoopService
*
LoopService
`inject:""`
OutputService
*
OutputService
`inject:""`
ExpressionService
*
ExpressionService
`inject:""`
LoopService
*
LoopService
`inject:""`
OutputService
*
OutputService
`inject:""`
PlaceholderService
*
PlaceholderService
`inject:""`
}
func
(
s
*
CombineService
)
CombineChildrenIfNeeded
(
field
*
model
.
DefField
)
{
...
...
internal/pkg/service/field.go
浏览文件 @
eda1ac10
...
...
@@ -18,6 +18,7 @@ type FieldService struct {
FixService
*
FixService
`inject:""`
LoopService
*
LoopService
`inject:""`
ListService
*
ListService
`inject:""`
RangeService
*
RangeService
`inject:""`
RandomService
*
RandomService
`inject:""`
}
...
...
@@ -123,7 +124,7 @@ func (s *FieldService) CreateField(field *model.DefField) {
}
if
field
.
Type
==
consts
.
FieldTypeList
{
s
.
CreateListFieldValues
(
field
)
s
.
ListService
.
CreateListFieldValues
(
field
)
}
else
if
field
.
Type
==
consts
.
FieldTypeArticle
{
s
.
ArticleService
.
CreateArticleField
(
field
)
...
...
@@ -136,14 +137,6 @@ func (s *FieldService) CreateField(field *model.DefField) {
return
}
func
(
s
*
FieldService
)
CreateListFieldValues
(
field
*
model
.
DefField
)
{
if
strings
.
Index
(
field
.
Range
,
".txt"
)
>
-
1
{
s
.
TextService
.
CreateFieldValuesFromText
(
field
)
}
else
{
s
.
RangeService
.
CreateFieldValuesFromRange
(
field
)
}
}
func
(
s
*
FieldService
)
GenValuesForConfig
(
field
*
model
.
DefField
)
(
values
[]
interface
{})
{
groupValues
:=
vari
.
GlobalVars
.
ResData
[
field
.
Config
]
...
...
internal/pkg/service/list.go
0 → 100644
浏览文件 @
eda1ac10
package
service
import
(
"github.com/easysoft/zendata/internal/pkg/model"
"strings"
)
type
ListService
struct
{
TextService
*
TextService
`inject:""`
RangeService
*
RangeService
`inject:""`
}
func
(
s
*
ListService
)
CreateListField
(
field
*
model
.
DefField
)
{
if
len
(
field
.
Fields
)
>
0
{
for
_
,
child
:=
range
field
.
Fields
{
s
.
CreateListField
(
&
child
)
}
}
else
{
s
.
CreateListFieldValues
(
field
)
}
}
func
(
s
*
ListService
)
CreateListFieldValues
(
field
*
model
.
DefField
)
{
if
strings
.
Index
(
field
.
Range
,
".txt"
)
>
-
1
{
s
.
TextService
.
CreateFieldValuesFromText
(
field
)
}
else
{
s
.
RangeService
.
CreateFieldValuesFromRange
(
field
)
}
}
internal/pkg/service/output-json.go
浏览文件 @
eda1ac10
...
...
@@ -8,7 +8,8 @@ import (
)
type
OutputService
struct
{
CombineService
*
CombineService
`inject:""`
CombineService
*
CombineService
`inject:""`
PlaceholderService
*
PlaceholderService
`inject:""`
}
func
(
s
*
OutputService
)
GenJson
(
def
*
model
.
DefData
)
{
...
...
@@ -36,10 +37,13 @@ func (s *OutputService) GenJson(def *model.DefData) {
}
func
(
s
*
OutputService
)
GenFieldMap
(
field
*
model
.
DefField
,
mp
*
map
[
string
]
interface
{},
i
int
)
{
if
field
.
Union
||
len
(
field
.
Fields
)
==
0
{
(
*
mp
)[
field
.
Field
]
=
field
.
Values
[
i
%
len
(
field
.
Values
)]
if
field
.
Union
||
len
(
field
.
Fields
)
==
0
{
// set values
val
:=
field
.
Values
[
i
%
len
(
field
.
Values
)]
val
=
s
.
PlaceholderService
.
ReplacePlaceholder
(
val
.
(
string
))
}
else
{
(
*
mp
)[
field
.
Field
]
=
val
}
else
{
// set child object
childMap
:=
map
[
string
]
interface
{}{}
for
_
,
child
:=
range
field
.
Fields
{
...
...
internal/pkg/service/output-rows.go
浏览文件 @
eda1ac10
...
...
@@ -14,7 +14,9 @@ func (s *OutputService) GenRows(def *model.DefData) {
s
.
CombineService
.
CombineChildrenIfNeeded
(
&
simulatedFieldFromDef
)
for
_
,
item
:=
range
simulatedFieldFromDef
.
Values
{
logUtils
.
PrintLine
(
item
.
(
string
)
+
"
\n
"
)
line
:=
s
.
PlaceholderService
.
ReplacePlaceholder
(
item
.
(
string
))
logUtils
.
PrintLine
(
line
+
"
\n
"
)
}
return
...
...
internal/pkg/service/placeholder.go
0 → 100644
浏览文件 @
eda1ac10
package
service
import
(
"fmt"
"github.com/easysoft/zendata/internal/pkg/gen/helper"
"github.com/easysoft/zendata/pkg/utils/vari"
"regexp"
"strconv"
"strings"
)
type
PlaceholderService
struct
{
}
func
(
s
*
PlaceholderService
)
ReplacePlaceholder
(
val
string
)
(
ret
string
)
{
ret
=
val
re
:=
regexp
.
MustCompile
(
"(?siU)
\\
${(.*)}"
)
matchResultArr
:=
re
.
FindAllStringSubmatch
(
ret
,
-
1
)
matchTimes
:=
len
(
matchResultArr
)
for
_
,
childArr
:=
range
matchResultArr
{
placeholderStr
:=
childArr
[
1
]
values
:=
s
.
getValForPlaceholder
(
placeholderStr
,
matchTimes
)
for
_
,
str
:=
range
values
{
key
,
_
:=
strconv
.
Atoi
(
placeholderStr
)
temp
:=
s
.
PlaceholderStr
(
key
)
ret
=
strings
.
Replace
(
ret
,
temp
,
str
,
1
)
}
}
return
}
func
(
s
*
PlaceholderService
)
getValForPlaceholder
(
placeholderStr
string
,
count
int
)
[]
string
{
placeholderNo
,
_
:=
strconv
.
Atoi
(
placeholderStr
)
mp
:=
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
placeholderNo
]
tp
:=
mp
[
"type"
]
.
(
string
)
repeatObj
:=
mp
[
"repeat"
]
repeat
:=
1
if
repeatObj
!=
nil
{
repeat
=
repeatObj
.
(
int
)
}
strArr
:=
make
([]
string
,
0
)
repeatTag
:=
mp
[
"repeatTag"
]
.
(
string
)
if
tp
==
"int"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strArr
=
helper
.
GetRandFromRange
(
"int"
,
start
,
end
,
"1"
,
repeat
,
repeatTag
,
precision
,
format
,
count
)
}
else
if
tp
==
"float"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
stepStr
:=
fmt
.
Sprintf
(
"%v"
,
mp
[
"step"
])
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strArr
=
helper
.
GetRandFromRange
(
"float"
,
start
,
end
,
stepStr
,
repeat
,
repeatTag
,
precision
,
format
,
count
)
}
else
if
tp
==
"char"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strArr
=
helper
.
GetRandFromRange
(
"char"
,
start
,
end
,
"1"
,
repeat
,
repeatTag
,
precision
,
format
,
count
)
}
else
if
tp
==
"list"
{
list
:=
mp
[
"list"
]
.
([]
string
)
strArr
=
helper
.
GetRandFromList
(
list
,
repeat
,
count
)
}
strArr
=
strArr
[
:
count
]
return
strArr
}
func
(
s
*
PlaceholderService
)
PlaceholderStr
(
key
int
)
string
{
return
fmt
.
Sprintf
(
"${%d}"
,
key
)
}
func
(
s
*
PlaceholderService
)
PlaceholderMapForRandValues
(
tp
string
,
list
[]
string
,
start
,
end
,
step
,
precision
,
format
string
,
repeat
int
,
repeatTag
string
)
map
[
string
]
interface
{}
{
ret
:=
map
[
string
]
interface
{}{}
ret
[
"type"
]
=
tp
// for literal values
ret
[
"list"
]
=
list
// for interval values
ret
[
"start"
]
=
start
ret
[
"end"
]
=
end
ret
[
"step"
]
=
step
ret
[
"precision"
]
=
precision
ret
[
"format"
]
=
format
ret
[
"repeat"
]
=
repeat
ret
[
"repeatTag"
]
=
repeatTag
return
ret
}
func
(
s
*
PlaceholderService
)
GetRandFieldSectionKey
(
pth
string
)
(
key
int
)
{
max
:=
0
for
k
,
v
:=
range
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
{
if
pth
==
v
{
key
=
k
return
}
if
k
>
max
{
max
=
k
}
}
if
key
==
0
{
key
=
max
+
1
}
return
}
internal/pkg/service/range.go
浏览文件 @
eda1ac10
...
...
@@ -18,6 +18,7 @@ import (
)
type
RangeService
struct
{
PlaceholderService
*
PlaceholderService
`inject:""`
}
func
(
s
*
RangeService
)
CreateFieldValuesFromRange
(
field
*
model
.
DefField
)
{
...
...
@@ -86,11 +87,11 @@ func (s *RangeService) CreateValuesFromLiteral(field *model.DefField, desc strin
key
:=
helper
.
GetRandFieldSection
(
pth
)
items
=
append
(
items
,
gen
.
Placeholder
(
key
))
mp
:=
gen
.
PlaceholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
mp
:=
s
.
PlaceholderService
.
PlaceholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
field
.
Format
,
repeat
,
repeatTag
)
vari
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
return
}
...
...
@@ -144,7 +145,7 @@ func (s *RangeService) CreateValuesFromInterval(field *model.DefField, desc, ste
pth
:=
field
.
Path
+
"->"
+
desc
key
:=
helper
.
GetRandFieldSection
(
pth
)
val
:=
gen
.
Placeholde
r
(
key
)
val
:=
s
.
PlaceholderService
.
PlaceholderSt
r
(
key
)
strItems
:=
make
([]
string
,
0
)
//for i := 0; i < repeat*count; i++ { // chang to add only one placeholder item
...
...
@@ -152,11 +153,11 @@ func (s *RangeService) CreateValuesFromInterval(field *model.DefField, desc, ste
strItems
=
append
(
strItems
,
val
)
//}
mp
:=
gen
.
PlaceholderMapForRandValues
(
dataType
,
strItems
,
startStr
,
endStr
,
fmt
.
Sprintf
(
"%v"
,
step
),
mp
:=
s
.
PlaceholderService
.
PlaceholderMapForRandValues
(
dataType
,
strItems
,
startStr
,
endStr
,
fmt
.
Sprintf
(
"%v"
,
step
),
strconv
.
Itoa
(
precision
),
field
.
Format
,
repeat
,
repeatTag
)
vari
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
vari
.
GlobalVars
.
RandFieldSectionShortKeysToPathMap
[
key
]
=
pth
vari
.
GlobalVars
.
RandFieldSectionPathToValuesMap
[
key
]
=
mp
return
}
...
...
pkg/utils/vari/var.go
浏览文件 @
eda1ac10
...
...
@@ -20,16 +20,22 @@ type GenVarType struct {
DefData
model
.
DefData
ResData
map
[
string
]
map
[
string
][]
interface
{}
CacheResFileToMap
map
[
string
]
map
[
string
][]
interface
{}
StartTime
time
.
Time
EndTime
time
.
Time
CacheResFileToMap
map
[
string
]
map
[
string
][]
interface
{}
RandFieldSectionPathToValuesMap
map
[
int
]
map
[
string
]
interface
{}
RandFieldSectionShortKeysToPathMap
map
[
int
]
string
StartTime
time
.
Time
EndTime
time
.
Time
}
var
(
GlobalVars
=
GenVarType
{
DefData
:
model
.
DefData
{},
CacheResFileToMap
:
map
[
string
]
map
[
string
][]
interface
{}{},
OutputFormat
:
consts
.
FormatText
,
DefData
:
model
.
DefData
{},
OutputFormat
:
consts
.
FormatText
,
CacheResFileToMap
:
map
[
string
]
map
[
string
][]
interface
{}{},
RandFieldSectionPathToValuesMap
:
map
[
int
]
map
[
string
]
interface
{}{},
RandFieldSectionShortKeysToPathMap
:
map
[
int
]
string
{},
}
)
...
...
@@ -70,11 +76,9 @@ var (
Ip
string
Port
int
ResLoading
=
false
Res
=
map
[
string
]
map
[
string
][]
string
{}
RandFieldSectionPathToValuesMap
=
map
[
int
]
map
[
string
]
interface
{}{}
RandFieldSectionShortKeysToPathMap
=
map
[
int
]
string
{}
TopFieldMap
=
map
[
string
]
model
.
DefField
{}
ResLoading
=
false
Res
=
map
[
string
]
map
[
string
][]
string
{}
TopFieldMap
=
map
[
string
]
model
.
DefField
{}
CacheResFileToMap
=
map
[
string
]
map
[
string
][]
string
{}
CacheResFileToName
=
map
[
string
]
string
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录