Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
fbd1f9d5
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 搜索 >>
提交
fbd1f9d5
编写于
6月 19, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gen map style json
上级
48054864
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
12 deletion
+85
-12
demo/article.yaml
demo/article.yaml
+40
-0
res/doc/sample.txt
res/doc/sample.txt
+2
-2
res/doc/usage.txt
res/doc/usage.txt
+5
-3
src/action/generator.go
src/action/generator.go
+33
-7
src/utils/vari/var.go
src/utils/vari/var.go
+2
-0
src/zd.go
src/zd.go
+3
-0
未找到文件。
demo/article.yaml
0 → 100644
浏览文件 @
fbd1f9d5
title
:
test
desc
:
wordpress article publis.
author
:
zentao
version
:
1.0
fields
:
-
field
:
title
note
:
文章标题
postfix
:
"
,
"
fields
:
-
field
:
title1
type
:
list
range
:
"
Title"
postfix
:
"
-"
-
field
:
title2
range
:
1-999
format
:
"
%03d"
-
field
:
content
node
:
文章内容
fields
:
-
field
:
field4.1
type
:
list
range
:
[
Epic
,
Feature
,
Story
]
:R{1}
prefix
:
"
<h5>"
postfix
:
"
:</h5>"
-
field
:
field4.2
postfix
:
"
<br/>Aaron
2020/06/18"
fields
:
-
field
:
field4.2.1
loop
:
3
fields
:
-
field
:
field4.2.1.1
postfix
:
"
<br/>"
loop
:
3
fields
:
-
field
:
field4.2.2
range
:
a-z:R
postfix
:
"
"
loop
:
6
res/doc/sample.txt
浏览文件 @
fbd1f9d5
...
...
@@ -3,8 +3,8 @@
$>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/output.txt -f text
执行数据生成命令。使用配置文件demo/test.yaml,生成15行数据,以text格式的输出到demo/output.txt文件中。
$>zd.exe -y demo/test.yaml -
c 15
-s
执行数据生成命令。
使用配置文件demo/test.yaml,生成15行数据,以行列的json形式输出到http://<ip_address
/data接口。
$>zd.exe -y demo/test.yaml -
head -sep ,
-s
执行数据生成命令。
带逗号分隔的标题行,默认生成10行,以Map形式的JSON格式输出到http://127.0.0.1
/data接口。
$>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/insert.sql -f sql -t table_name
执行数据生成命令。以SQL语句形式输出到demo/insert.sql文件中,表名为table_name。
...
...
res/doc/usage.txt
浏览文件 @
fbd1f9d5
...
...
@@ -8,9 +8,11 @@
--field 需要输出的字段,用逗号分隔。未指定时,默认输出-yaml文件中的所有字段。
-o --out 指定输出文件
-f --format 输出格式,支持text、json、xml和sql语句,默认为text。
-t --table 输出格式为table时,用于指定insert语句的表名
-s --service 启动http服务,用户可从http://<ip_address/data接口获取json格式的行列数据。
--verbose 增加此参数,显示详细调试信息。
-t --table 输出格式为table时,用于指定insert语句的表名。
--head 生成标题行。文本格式增加标题行,JSON数据转化为Map格式(JSON默认为二维数组)。
--sep 生成标题行时,纸短见的分隔符,默认为逗号。
-s --service 启动http服务,用户可从http://<ip_address/data接口获取JSON格式的行列数据。
--verbose 增加此参数,显示详细调试信息。
为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。
https://www.ztesting.net/book/ztf-doc/add-to-path-46.html
\ No newline at end of file
src/action/generator.go
浏览文件 @
fbd1f9d5
...
...
@@ -61,6 +61,18 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
content
:=
""
sql
:=
""
if
vari
.
WithHead
{
line
:=
""
for
idx
,
field
:=
range
fields
{
line
+=
field
if
idx
<
len
(
fields
)
-
1
{
line
+=
vari
.
HeadSep
}
}
logUtils
.
Screen
(
fmt
.
Sprintf
(
"%s"
,
line
))
content
+=
line
+
"
\n
"
}
testData
:=
model
.
TestData
{}
testData
.
Title
=
"Test Data"
...
...
@@ -102,23 +114,37 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
}
}
jsonStr
:=
"[]"
respJson
:=
"[]"
if
format
==
"json"
||
vari
.
HttpService
{
jsonObj
,
_
:=
json
.
Marshal
(
rows
)
content
=
string
(
jsonObj
)
if
vari
.
HttpService
{
jsonStr
=
content
if
vari
.
WithHead
{
mapObj
:=
RowsToMap
(
rows
,
fields
)
jsonObj
,
_
:=
json
.
Marshal
(
mapObj
)
respJson
=
string
(
jsonObj
)
}
else
{
jsonObj
,
_
:=
json
.
Marshal
(
rows
)
respJson
=
string
(
jsonObj
)
}
}
if
format
==
"xml"
{
if
format
==
"json"
{
content
=
respJson
}
else
if
format
==
"xml"
{
xml
,
_
:=
xml
.
Marshal
(
testData
)
content
=
string
(
xml
)
}
else
if
format
==
"sql"
{
content
=
sql
}
return
content
,
jsonStr
return
content
,
respJson
}
func
RowsToMap
(
rows
[][]
string
,
fieldsToExport
[]
string
)
(
ret
map
[
string
]
string
)
{
for
_
,
cols
:=
range
rows
{
for
j
,
col
:=
range
cols
{
ret
[
fieldsToExport
[
j
]]
=
col
}
}
return
}
func
DataHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
src/utils/vari/var.go
浏览文件 @
fbd1f9d5
...
...
@@ -22,6 +22,8 @@ var (
Verbose
bool
Interpreter
string
WithHead
bool
HeadSep
string
HttpService
bool
JsonResp
string
=
"[]"
)
src/zd.go
浏览文件 @
fbd1f9d5
...
...
@@ -69,6 +69,9 @@ func main() {
flagSet
.
StringVar
(
&
viewRes
,
"v"
,
""
,
""
)
flagSet
.
StringVar
(
&
viewDetail
,
"vv"
,
""
,
""
)
flagSet
.
BoolVar
(
&
vari
.
WithHead
,
"head"
,
false
,
""
)
flagSet
.
StringVar
(
&
vari
.
HeadSep
,
"sep"
,
","
,
""
)
flagSet
.
BoolVar
(
&
vari
.
HttpService
,
"s"
,
false
,
""
)
flagSet
.
BoolVar
(
&
vari
.
Verbose
,
"verbose"
,
false
,
""
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录