Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
9a64c743
Z
zendata
项目概览
LinuxSuRen
/
zendata
与 Fork 源项目一致
Fork自
易企天创 / zendata
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9a64c743
编写于
8月 28, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some issues
上级
18f81227
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
12 deletion
+36
-12
demo/default.yaml
demo/default.yaml
+1
-1
src/gen/list.go
src/gen/list.go
+4
-3
src/gen/output.go
src/gen/output.go
+6
-3
src/gen/rand.go
src/gen/rand.go
+25
-5
未找到文件。
demo/default.yaml
浏览文件 @
9a64c743
...
...
@@ -93,7 +93,7 @@ fields:
postfix
:
"
\t
"
-
field
:
field_format
# 通过格式化字符串输出。
range
:
1-10
# passwd 1,passwd 2,passwd 3 ... passwd10。
range
:
1-10
:R
# passwd 1,passwd 2,passwd 3 ... passwd10。
format
:
"
passwd%02d"
# 用%2d补零,使密码整体保持8位,%2d默认补空格。
postfix
:
"
\t
"
...
...
src/gen/list.go
浏览文件 @
9a64c743
...
...
@@ -166,7 +166,7 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
if
field
.
Path
!=
""
&&
stepStr
==
"r"
{
items
=
append
(
items
,
Placeholder
(
field
.
Path
))
mp
:=
placeholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
)
mp
:=
placeholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
field
.
Format
)
vari
.
RandFieldNameToValuesMap
[
field
.
Path
]
=
mp
return
...
...
@@ -208,7 +208,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
if
field
.
Path
!=
""
&&
dataType
!=
"string"
&&
rand
{
// random
items
=
append
(
items
,
Placeholder
(
field
.
Path
))
mp
:=
placeholderMapForRandValues
(
dataType
,
[]
string
{},
startStr
,
endStr
,
stepStr
,
strconv
.
Itoa
(
precision
))
mp
:=
placeholderMapForRandValues
(
dataType
,
[]
string
{},
startStr
,
endStr
,
stepStr
,
strconv
.
Itoa
(
precision
)
,
field
.
Format
)
vari
.
RandFieldNameToValuesMap
[
field
.
Path
]
=
mp
return
...
...
@@ -274,7 +274,7 @@ func Placeholder(str string) string {
return
"${"
+
str
+
"}"
}
func
placeholderMapForRandValues
(
tp
string
,
list
[]
string
,
start
,
end
,
step
,
precision
string
)
map
[
string
]
interface
{}
{
func
placeholderMapForRandValues
(
tp
string
,
list
[]
string
,
start
,
end
,
step
,
precision
,
format
string
)
map
[
string
]
interface
{}
{
ret
:=
map
[
string
]
interface
{}{}
ret
[
"type"
]
=
tp
...
...
@@ -285,6 +285,7 @@ func placeholderMapForRandValues(tp string, list []string, start, end, step, pre
ret
[
"end"
]
=
end
ret
[
"step"
]
=
step
ret
[
"precision"
]
=
precision
ret
[
"format"
]
=
format
return
ret
}
src/gen/output.go
浏览文件 @
9a64c743
...
...
@@ -195,20 +195,23 @@ func getValForPlaceholder(placeholderStr string, count int) []string {
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
GetRandFromRange
(
"int"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
)
strs
=
GetRandFromRange
(
"int"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
}
else
if
tp
==
"float"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
GetRandFromRange
(
"float"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
)
strs
=
GetRandFromRange
(
"float"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
}
else
if
tp
==
"char"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
GetRandFromRange
(
"char"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
)
strs
=
GetRandFromRange
(
"char"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
}
else
if
tp
==
"list"
{
list
:=
mp
[
"list"
]
.
([]
string
)
strs
=
GetRandFromList
(
list
,
repeat
,
count
)
...
...
src/gen/rand.go
浏览文件 @
9a64c743
...
...
@@ -2,6 +2,7 @@ package gen
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"strconv"
"strings"
)
...
...
@@ -25,7 +26,7 @@ func GetRandFromList(list []string, repeatStr string, count int) []string {
return
ret
}
func
GetRandFromRange
(
dataType
,
start
,
end
,
step
,
repeatStr
,
precisionStr
string
,
count
int
)
[]
string
{
func
GetRandFromRange
(
dataType
,
start
,
end
,
step
,
repeatStr
,
precisionStr
string
,
count
int
,
format
string
)
[]
string
{
repeat
,
_
:=
strconv
.
Atoi
(
repeatStr
)
precision
,
_
:=
strconv
.
Atoi
(
precisionStr
)
...
...
@@ -50,8 +51,14 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
val
:=
startInt
+
rand
items
:=
make
([]
string
,
0
)
item
:=
strconv
.
FormatInt
(
val
,
10
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
)
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
strconv
.
FormatInt
(
val
,
10
)
)
items
=
append
(
items
,
item
)
}
temp
:=
strings
.
Join
(
items
,
""
)
...
...
@@ -75,8 +82,15 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
}
val
:=
startChar
+
byte
(
rand
)
items
:=
make
([]
string
,
0
)
item
:=
string
(
val
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
)
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
string
(
val
)
)
items
=
append
(
items
,
item
)
}
temp
:=
strings
.
Join
(
items
,
""
)
...
...
@@ -103,9 +117,15 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
val
:=
startFloat
+
float64
(
rand
)
*
stepFloat
items
:=
make
([]
string
,
0
)
item
:=
strconv
.
FormatFloat
(
val
,
'f'
,
precision
,
64
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
)
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
str
:=
strconv
.
FormatFloat
(
val
,
'f'
,
precision
,
64
)
items
=
append
(
items
,
str
)
items
=
append
(
items
,
item
)
}
temp
:=
strings
.
Join
(
items
,
""
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录