Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
f33777f0
Z
zendata
项目概览
易企天创
/
zendata
8 个月 前同步成功
通知
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 搜索 >>
提交
f33777f0
编写于
7月 20, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
decode with pre/post fix
上级
bfb4a0ae
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
182 addition
and
99 deletion
+182
-99
demo/test.yaml
demo/test.yaml
+6
-6
res/doc/usage.txt
res/doc/usage.txt
+5
-1
res/doc/usage_en.txt
res/doc/usage_en.txt
+3
-0
res/messages_en.json
res/messages_en.json
+4
-0
res/messages_zh.json
res/messages_zh.json
+4
-0
res/res.go
res/res.go
+34
-10
src/gen/analyse.go
src/gen/analyse.go
+0
-61
src/gen/decode.go
src/gen/decode.go
+102
-0
src/utils/common/utils.go
src/utils/common/utils.go
+1
-1
src/zd.go
src/zd.go
+5
-5
test/unit/test.go
test/unit/test.go
+14
-11
xdoc/4-build.sh
xdoc/4-build.sh
+4
-4
未找到文件。
demo/test.yaml
浏览文件 @
f33777f0
...
...
@@ -5,17 +5,17 @@ version: 1.0
fields
:
-
field
:
field_use_instance
# 引用default.xml里的嵌套字段
length
:
16
prefix
:
"
["
# 复写前缀
postfix
:
"
]"
# 特殊字符加引号,否则无法解析
-
field
:
field_use_excel
prefix
:
"
==="
# 复写前缀
prefix
:
"
["
# 复写前缀
postfix
:
"
]
"
# 特殊字符加引号,否则无法解析
-
field
:
field_with_children
prefix
:
"
["
# 复写前缀
postfix
:
"
]
"
# 复写后缀
length
:
40
postfix
:
"
]
"
# 特殊字符加引号,否则无法解析
-
field
:
field_loop
# 引用default.xml里的自循环的字段
prefix
:
"
["
# 复写前缀
prefix
:
"
["
# 复写前缀
postfix
:
"
]"
# 特殊字符加引号,否则无法解析
length
:
8
res/doc/usage.txt
浏览文件 @
f33777f0
...
...
@@ -10,12 +10,15 @@ zendata是一款通用的数据生成工具,您可以使用yaml文件来定义
-F --field 可通过该参数指定要输出的字段列表,用逗号分隔。 默认是所有的字段。
-t --table 输出格式为sql时,需通过该参数指定要插入数据的表名。
-H --human 输出可读格式,打印字段名,并使用tab键进行分割。
-r --recursive 递归模式。如不指定,默认为平行模式。平行模式下各个字段独立循环。
递归模式下每个字段的取值依赖于前一字段。可增强数据的随机性。
-p --port 在指定端口上运行HTTP服务。可通过http://ip/接口获得JSON格式的数据。服务模式下只支持数据生成。
-b --bind 监听的ip地址,默认监听所有的ip地址。
-R --root 运行HTTP服务时根目录。客户端可调用该根目录下面的配置文件。如果不指定,取zd可执行文件所在目录。
-i --input 指定一个schema文件,输出每个表的yaml配置文件。需通过-o参数指定一个输出的目录。
-D --decode 根据指定的配置文件,将通过-i参数指定的数据文件解析成json格式。
-e --example 打印示例的数据格式配置文件。
-l --list 列出所有支持的数据格式。
...
...
@@ -33,7 +36,8 @@ $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.json 输出json
$>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.xml 输出xml格式的数据。
$>zd.exe -d demo\default.yaml -n 100 -o test.sql -t user -s mysql 输出插入到user表里面的sql。
$>zd.exe -i db.sql -s mysql -o db 根据db.sql的定义生成每个表的yaml文件,存储到db目录里面。
$>zd.exe -i db.sql -o db 根据db.sql的定义生成每个表的yaml文件,存储到db目录里面。
$>zd.exe -c demo\default.yaml -i test.txt --decode 将-i指定的文件根据-d参数的配置进行解析。
$>zd.exe -l # 列出所有內置数据。
$>zd.exe -v system.address.v1 # 查看內置Excel文件system/address/v1.xlsx中的数据表。
...
...
res/doc/usage_en.txt
浏览文件 @
f33777f0
...
...
@@ -25,6 +25,8 @@ Parameters
-i --input Specify a sql schema file and output the YAML config file for each table.
You need to specify an output directory by using -o.
-D --decode Referring to the specified configuration file, parse the data file specified by -i and output json.
Also you can output the readable format via -H.
-e --example Print the data format config file of the example.
-l --list List all supported data formats.
...
...
@@ -43,6 +45,7 @@ $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.xml # Output da
$>zd.exe -d demo/default.yaml -n 100 -o test.sql -t user -s mysql # Output the sql inserted into the table user.
$>zd.exe -i db.sql -o db # Generate YAML files for each table by parsing db.sql and store them in the db directory.
$>zd.exe -c demo/default.yaml -i test.txt --decode # Parse the file specified by -i according to the config of -d.
$>zd.exe -l # List all build-in data types.
$>zd.exe -v system.address.v1 # View data types in build-in Excel file system/address/v1.xlsx.
...
...
res/messages_en.json
浏览文件 @
f33777f0
...
...
@@ -108,6 +108,10 @@
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel that contains below data."
},
{
"id"
:
"analyse_success"
,
"translation"
:
"Success to decode data to %s."
}
]
}
\ No newline at end of file
res/messages_zh.json
浏览文件 @
f33777f0
...
...
@@ -99,6 +99,10 @@
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel数据源,包含以下内容."
},
{
"id"
:
"analyse_success"
,
"translation"
:
"成功解析数据到%s."
}
]
}
\ No newline at end of file
res/res.go
浏览文件 @
f33777f0
此差异已折叠。
点击以展开。
src/gen/analyse.go
已删除
100644 → 0
浏览文件 @
bfb4a0ae
package
gen
import
(
"encoding/json"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
"github.com/easysoft/zendata/src/utils/vari"
"strings"
)
const
(
)
func
Analyse
(
output
,
fieldsToExportStr
,
configFile
,
defaultFile
string
)
{
fieldsToExport
:=
make
([]
string
,
0
)
if
fieldsToExportStr
!=
""
{
fieldsToExport
=
strings
.
Split
(
fieldsToExportStr
,
","
)
}
vari
.
Def
=
LoadConfigDef
(
defaultFile
,
configFile
,
&
fieldsToExport
)
vari
.
Res
=
LoadResDef
(
fieldsToExport
)
data
:=
fileUtils
.
ReadFile
(
output
)
mapArr
:=
LinesToMap
(
data
,
fieldsToExport
)
jsonObj
,
_
:=
json
.
Marshal
(
mapArr
)
respJson
:=
string
(
jsonObj
)
path
:=
output
[
:
strings
.
LastIndex
(
output
,
"."
)]
+
".json"
fileUtils
.
WriteFile
(
path
,
respJson
)
}
func
LinesToMap
(
str
string
,
fieldsToExport
[]
string
)
(
ret
[]
map
[
string
]
string
)
{
start
:=
0
if
vari
.
WithHead
{
start
=
1
}
ret
=
[]
map
[
string
]
string
{}
for
index
,
line
:=
range
strings
.
Split
(
str
,
"
\n
"
)
{
if
index
<
start
{
continue
}
rowMap
:=
map
[
string
]
string
{}
left
:=
line
for
j
,
field
:=
range
vari
.
Def
.
Fields
{
col
:=
""
// TODO: use post/pre fix to seperate
col
=
left
[
:
field
.
Width
]
left
=
left
[
field
.
Width
:
]
rowMap
[
fieldsToExport
[
j
]]
=
col
}
ret
=
append
(
ret
,
rowMap
)
}
return
}
\ No newline at end of file
src/gen/decode.go
0 → 100644
浏览文件 @
f33777f0
package
gen
import
(
"encoding/json"
"github.com/easysoft/zendata/src/model"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"strings"
)
const
(
)
func
Decode
(
defaultFile
,
configFile
,
fieldsToExportStr
,
input
,
output
string
)
{
fieldsToExport
:=
make
([]
string
,
0
)
if
fieldsToExportStr
!=
""
{
fieldsToExport
=
strings
.
Split
(
fieldsToExportStr
,
","
)
}
vari
.
Def
=
LoadConfigDef
(
defaultFile
,
configFile
,
&
fieldsToExport
)
vari
.
Res
=
LoadResDef
(
fieldsToExport
)
data
:=
fileUtils
.
ReadFile
(
input
)
ret
:=
[]
map
[
string
]
interface
{}{}
LinesToMap
(
data
,
fieldsToExport
,
&
ret
)
jsonObj
,
_
:=
json
.
Marshal
(
ret
)
respJson
:=
string
(
jsonObj
)
fileUtils
.
WriteFile
(
output
,
respJson
)
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"analyse_success"
,
output
))
}
func
LinesToMap
(
str
string
,
fieldsToExport
[]
string
,
ret
*
[]
map
[
string
]
interface
{})
{
start
:=
0
if
vari
.
WithHead
{
start
=
1
}
for
index
,
line
:=
range
strings
.
Split
(
str
,
"
\n
"
)
{
if
index
<
start
{
continue
}
rowMap
:=
decodeOnLevel
(
line
,
fieldsToExport
,
vari
.
Def
.
Fields
)
*
ret
=
append
(
*
ret
,
rowMap
)
}
return
}
func
decodeOnLevel
(
line
string
,
fieldsToExport
[]
string
,
fields
[]
model
.
DefField
)
(
ret
map
[
string
]
interface
{})
{
ret
=
map
[
string
]
interface
{}{}
left
:=
[]
rune
(
line
)
for
j
,
field
:=
range
fields
{
col
:=
""
if
field
.
Width
>
0
{
col
=
string
(
left
[
:
field
.
Width
])
left
=
left
[
field
.
Width
:
]
}
else
{
sepStr
:=
""
if
j
<
len
(
vari
.
Def
.
Fields
)
-
1
{
sepStr
=
field
.
Postfix
+
vari
.
Def
.
Fields
[
j
+
1
]
.
Prefix
}
else
{
sepStr
=
field
.
Postfix
}
sep
:=
[]
rune
(
sepStr
)
if
len
(
sep
)
>
0
{
index
:=
searchRune
(
left
,
sep
)
if
index
>
-
1
{
col
=
string
(
left
[
:
index
+
runewidth
.
StringWidth
(
field
.
Postfix
)])
left
=
left
[
index
+
runewidth
.
StringWidth
(
field
.
Postfix
)
:
]
}
}
}
ret
[
fieldsToExport
[
j
]]
=
col
}
return
}
func
searchRune
(
text
[]
rune
,
what
[]
rune
)
int
{
for
i
:=
range
text
{
found
:=
true
for
j
:=
range
what
{
if
i
+
j
<
len
(
text
)
&&
text
[
i
+
j
]
!=
what
[
j
]
{
found
=
false
break
}
}
if
found
{
return
i
}
}
return
-
1
}
\ No newline at end of file
src/utils/common/utils.go
浏览文件 @
f33777f0
...
...
@@ -25,7 +25,7 @@ func RemoveBlankLine(str string) string {
ret
:=
myExp
.
ReplaceAllString
(
str
,
"
\n\n
"
)
ret
=
strings
.
Trim
(
ret
,
"
\n
"
)
ret
=
strings
.
TrimSpace
(
ret
)
//
ret = strings.TrimSpace(ret)
return
ret
}
...
...
src/zd.go
浏览文件 @
f33777f0
...
...
@@ -35,7 +35,7 @@ var (
output
string
table
string
format
=
constant
.
FormatText
analyse
string
decode
bool
listRes
bool
viewRes
string
...
...
@@ -91,8 +91,8 @@ func main() {
flagSet
.
StringVar
(
&
vari
.
HeadSep
,
"H"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
HeadSep
,
"human"
,
""
,
""
)
flagSet
.
StringVar
(
&
analyse
,
"a"
,
""
,
""
)
flagSet
.
StringVar
(
&
analyse
,
"analyse"
,
""
,
""
)
flagSet
.
BoolVar
(
&
decode
,
"D"
,
false
,
""
)
flagSet
.
BoolVar
(
&
decode
,
"decode"
,
false
,
""
)
flagSet
.
StringVar
(
&
vari
.
Ip
,
"b"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
Ip
,
"bind"
,
""
,
""
)
...
...
@@ -130,8 +130,8 @@ func main() {
}
else
if
md5
!=
""
{
service
.
AddMd5
(
md5
)
return
}
else
if
analyse
!=
""
{
gen
.
Analyse
(
output
,
fields
,
analyse
,
defaultFile
)
}
else
if
decode
{
gen
.
Decode
(
defaultFile
,
configFile
,
fields
,
input
,
output
)
return
}
...
...
test/unit/test.go
浏览文件 @
f33777f0
package
main
import
(
"github.com/easysoft/zendata/src/gen"
httpUtils
"github.com/easysoft/zendata/src/utils/http"
"io/ioutil"
"net/url"
"fmt"
"strings"
)
func
main
()
{
urlStr
:=
"http://127.0.0.1:8848/?F=field3&lines=12"
file
:=
"test/code/test.yaml"
//urlStr := "http://127.0.0.1:8848/?F=field3&lines=12"
//file := "test/code/test.yaml"
//
//yamlContent, _ := ioutil.ReadFile(file)
//yamlContent = gen.ReplaceSpecialChars(yamlContent)
//
//data := url.Values{"config": {string(yamlContent)}}
//httpUtils.PostForm(urlStr, data)
yamlContent
,
_
:=
ioutil
.
ReadFile
(
file
)
yamlContent
=
gen
.
ReplaceSpecialChars
(
yamlContent
)
data
:=
url
.
Values
{
"config"
:
{
string
(
yamlContent
)}}
httpUtils
.
PostForm
(
urlStr
,
data
)
a
:=
"我的"
b
:=
"dsfdsfdf是我的吗"
index
:=
strings
.
Index
(
a
,
b
)
fmt
.
Println
(
index
)
}
xdoc/4-build.sh
浏览文件 @
f33777f0
cd
build
cp
zd-x86.exe zd.exe
zip
-r
zd-win-x86-1.1.zip zd.exe
conf
data demo
zip
-r
zd-win-x86-1.1.zip zd.exe data demo
rm
zd.exe
cp
zd-amd64.exe zd.exe
zip
-r
zd-win-amd64-1.1.zip zd.exe
conf
data demo
zip
-r
zd-win-amd64-1.1.zip zd.exe data demo
rm
zd.exe
cp
zd-linux zd
tar
-zcvf
zd-linux-1.1.tar.gz zd
conf
data demo
tar
-zcvf
zd-linux-1.1.tar.gz zd data demo
rm
zd
cp
zd-mac zd
zip
-r
zd-mac-1.1.zip zd
conf
data demo
zip
-r
zd-mac-1.1.zip zd data demo
rm
zd
cd
..
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录