Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
4c3a92fb
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 搜索 >>
提交
4c3a92fb
编写于
7月 20, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new features for 1.1
上级
0702e8e7
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
36 addition
and
53 deletion
+36
-53
res/doc/usage.txt
res/doc/usage.txt
+3
-5
res/doc/usage_en.txt
res/doc/usage_en.txt
+4
-1
src/action/generator.go
src/action/generator.go
+1
-2
src/gen/analyse.go
src/gen/analyse.go
+2
-2
src/gen/definition.go
src/gen/definition.go
+2
-2
src/gen/generator.go
src/gen/generator.go
+2
-2
src/model/definition.go
src/model/definition.go
+3
-1
src/service/md5.go
src/service/md5.go
+3
-4
src/service/request.go
src/service/request.go
+1
-5
src/utils/string/string.go
src/utils/string/string.go
+12
-12
src/utils/vari/var.go
src/utils/vari/var.go
+0
-4
src/zd.go
src/zd.go
+3
-13
未找到文件。
res/doc/usage.txt
浏览文件 @
4c3a92fb
...
...
@@ -10,14 +10,12 @@ zendata是一款通用的数据生成工具,您可以使用yaml文件来定义
-F --field 可通过该参数指定要输出的字段列表,用逗号分隔。 默认是所有的字段。
-t --table 输出格式为sql时,需通过该参数指定要插入数据的表名。
-H --human 输出可读格式,打印字段名,并使用tab键进行分割。
-W --width 生成的字符串宽度,默认侧补空格。
-P --leftPad 宽度不足时,左侧补充的字符,默认为空格。此参数为非空时,RightPad设置无效。
-R --rightPad 宽度不足时,右侧补充的字符,仅在LeftPad为空时有效。
-r --recursive 递归模式。如不指定,默认为平行模式。平行模式下各个字段独立循环。
递归模式下每个字段的取值依赖于前一字段。可增强数据的随机性。
-p --port 在指定端口上运行HTTP服务。可通过http://ip/接口获得JSON格式的数据。服务模式下只支持数据生成。
-b --bind 监听的ip地址,默认监听所有的ip地址。
-
r
--root 运行HTTP服务时根目录。客户端可调用该根目录下面的配置文件。如果不指定,取zd可执行文件所在目录。
-
R
--root 运行HTTP服务时根目录。客户端可调用该根目录下面的配置文件。如果不指定,取zd可执行文件所在目录。
-i --input 指定一个schema文件,输出每个表的yaml配置文件。需通过-o参数指定一个输出的目录。
-s --server 数据库服务器类型,支持mysql|oracle|sqlite|sqlserver,默认为mysql。可用于解析yaml文件或者生成SQL。
...
...
res/doc/usage_en.txt
浏览文件 @
4c3a92fb
...
...
@@ -14,10 +14,13 @@ Parameters
-t --table If the output format is sql, using it to specify the table name to insert data to.
-H --human Output a readable format, print the field name, and use the tab key to split.
-r --recursive Recursive mode. The default mode is parallel, in which each field loops independently.
The value of a field in the recursive mode depends on that of the previous field, which enables the random data.
-p --port Run the HTTP on the specified port. The data in JSON format can be obtained via http://ip/ port.
Only data generation is supported.
-b --bind Listen IP addresses. All IP addresses are listened by default.
-
r --root The root directory when running HTTP. The client can call the config file under the root directory.
-
R --root The root directory when running HTTP. The client can call the config file under the root directory.
If not specified, take the directory where the zd executable file is located.
-i --input Specify a sql schema file and output the YAML config file for each table.
...
...
src/action/generator.go
浏览文件 @
4c3a92fb
...
...
@@ -8,7 +8,6 @@ import (
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"strings"
)
...
...
@@ -74,7 +73,7 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
row
.
Cols
=
append
(
row
.
Cols
,
col
)
colVal
:=
col
colVal
=
stringUtils
.
AddPad
(
colVal
)
//colVal = stringUtils.AddPad(colVal, vari.Def.Fields[j]
)
if
!
colTypes
[
j
]
{
colVal
=
"'"
+
colVal
+
"'"
}
valueList
=
valueList
+
colVal
}
...
...
src/gen/analyse.go
浏览文件 @
4c3a92fb
...
...
@@ -49,8 +49,8 @@ func LinesToMap(str string, fieldsToExport []string) (ret []map[string]string) {
for
j
,
field
:=
range
vari
.
Def
.
Fields
{
col
:=
""
// TODO: use post/pre fix to seperate
col
=
left
[
:
field
.
Leng
th
]
left
=
left
[
field
.
Leng
th
:
]
col
=
left
[
:
field
.
Wid
th
]
left
=
left
[
field
.
Wid
th
:
]
rowMap
[
fieldsToExport
[
j
]]
=
col
}
...
...
src/gen/definition.go
浏览文件 @
4c3a92fb
...
...
@@ -164,8 +164,8 @@ func CopyField(child model.DefField, parent *model.DefField) {
if
child
.
Precision
!=
0
{
(
*
parent
)
.
Precision
=
child
.
Precision
}
if
child
.
Leng
th
!=
0
{
(
*
parent
)
.
Length
=
child
.
Leng
th
if
child
.
Wid
th
!=
0
{
(
*
parent
)
.
Width
=
child
.
Wid
th
}
}
...
...
src/gen/generator.go
浏览文件 @
4c3a92fb
...
...
@@ -228,8 +228,8 @@ func GenerateFieldValWithFix(field model.DefField, fieldValue model.FieldValue,
loopStr
=
prefix
+
loopStr
+
postfix
}
if
field
.
Leng
th
>
runewidth
.
StringWidth
(
loopStr
)
{
loopStr
=
loopStr
+
strings
.
Repeat
(
" "
,
field
.
Length
-
runewidth
.
StringWidth
(
loopStr
)
)
if
field
.
Wid
th
>
runewidth
.
StringWidth
(
loopStr
)
{
loopStr
=
stringUtils
.
AddPad
(
loopStr
,
field
)
}
return
loopStr
...
...
src/model/definition.go
浏览文件 @
4c3a92fb
...
...
@@ -34,7 +34,9 @@ type DefData struct {
type
DefField
struct
{
FieldBase
`yaml:",inline"`
Fields
[]
DefField
`yaml:"fields,flow"`
Length
int
`yaml:"length"`
Width
int
`yaml:"width"`
LeftPad
string
`yaml:"leftPad"`
RightPad
string
`yaml:"rightPad"`
Path
string
}
...
...
src/service/md5.go
浏览文件 @
4c3a92fb
...
...
@@ -14,7 +14,7 @@ const (
md5Col
=
"CW"
)
func
AddMd5
(
path
string
,
salt
string
)
{
func
AddMd5
(
path
string
)
{
excel
,
err
:=
excelize
.
OpenFile
(
path
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
path
))
...
...
@@ -46,7 +46,7 @@ func AddMd5(path string, salt string) {
val
:=
strings
.
TrimSpace
(
col
)
str
=
str
+
val
}
md5Str
:=
md5V
(
str
,
salt
)
md5Str
:=
md5V
(
str
)
excel
.
SetCellValue
(
sheet
,
md5Col
+
strconv
.
Itoa
(
index
+
1
),
md5Str
)
}
}
...
...
@@ -56,9 +56,8 @@ func AddMd5(path string, salt string) {
}
}
func
md5V
(
str
,
salt
string
)
string
{
func
md5V
(
str
string
)
string
{
h
:=
md5
.
New
()
h
.
Write
([]
byte
(
str
))
h
.
Write
([]
byte
(
salt
))
return
hex
.
EncodeToString
(
h
.
Sum
(
nil
))
}
\ No newline at end of file
src/service/request.go
浏览文件 @
4c3a92fb
...
...
@@ -10,7 +10,7 @@ import (
)
func
ParseRequestParams
(
req
*
http
.
Request
)
(
root
,
defaultFile
,
yamlFile
string
,
count
int
,
fields
,
human
string
,
width
int
,
leftPad
,
rightPad
,
format
,
table
string
)
{
fields
,
human
string
,
format
,
table
string
)
{
query
:=
req
.
URL
.
Query
()
root
=
GetRequestParams
(
query
,
"root"
,
"r"
)
...
...
@@ -24,10 +24,6 @@ func ParseRequestParams(req *http.Request) (root, defaultFile, yamlFile string,
table
=
""
human
=
GetRequestParams
(
query
,
"human"
,
"H"
)
widthStr
:=
GetRequestParams
(
query
,
"width"
,
"W"
)
width
,
_
=
strconv
.
Atoi
(
widthStr
)
leftPad
=
GetRequestParams
(
query
,
"leftPad"
,
"L"
)
rightPad
=
GetRequestParams
(
query
,
"rightPad"
,
"R"
)
req
.
ParseForm
()
defaultDefContent
:=
req
.
FormValue
(
"default"
)
...
...
src/utils/string/string.go
浏览文件 @
4c3a92fb
...
...
@@ -5,8 +5,8 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"strconv"
"strings"
...
...
@@ -109,20 +109,20 @@ func InArray(need interface{}, arr []string) bool {
return
false
}
func
AddPad
(
str
string
)
string
{
if
vari
.
Length
>
0
{
gap
:=
vari
.
Leng
th
-
len
(
str
)
if
vari
.
LeftPad
!=
""
{
vari
.
LeftPad
=
vari
.
LeftPad
[
:
1
]
pads
:=
strings
.
Repeat
(
vari
.
LeftPad
,
gap
)
func
AddPad
(
str
string
,
field
model
.
DefField
)
string
{
if
field
.
Width
>
0
&&
field
.
Width
>
runewidth
.
StringWidth
(
str
)
{
gap
:=
field
.
Wid
th
-
len
(
str
)
if
field
.
LeftPad
!=
""
{
field
.
LeftPad
=
field
.
LeftPad
[
:
1
]
pads
:=
strings
.
Repeat
(
field
.
LeftPad
,
gap
)
str
=
pads
+
str
}
else
if
vari
.
RightPad
!=
""
{
vari
.
RightPad
=
vari
.
RightPad
[
:
1
]
pads
:=
strings
.
Repeat
(
vari
.
RightPad
,
gap
)
}
else
if
field
.
RightPad
!=
""
{
field
.
RightPad
=
field
.
RightPad
[
:
1
]
pads
:=
strings
.
Repeat
(
field
.
RightPad
,
gap
)
str
=
str
+
pads
}
else
{
vari
.
LeftPad
=
" "
pads
:=
strings
.
Repeat
(
vari
.
LeftPad
,
gap
)
field
.
LeftPad
=
" "
pads
:=
strings
.
Repeat
(
field
.
LeftPad
,
gap
)
str
=
pads
+
str
}
}
...
...
src/utils/vari/var.go
浏览文件 @
4c3a92fb
...
...
@@ -23,10 +23,6 @@ var (
WithHead
bool
HeadSep
string
Length
int
LeftPad
string
RightPad
string
JsonResp
string
=
"[]"
Ip
string
Port
int
...
...
src/zd.go
浏览文件 @
4c3a92fb
...
...
@@ -41,7 +41,6 @@ var (
viewRes
string
viewDetail
string
md5
string
salt
string
example
bool
help
bool
...
...
@@ -88,7 +87,6 @@ func main() {
flagSet
.
StringVar
(
&
viewRes
,
"view"
,
""
,
""
)
flagSet
.
StringVar
(
&
md5
,
"md5"
,
""
,
""
)
flagSet
.
StringVar
(
&
salt
,
"salt"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
HeadSep
,
"H"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
HeadSep
,
"human"
,
""
,
""
)
...
...
@@ -96,18 +94,11 @@ func main() {
flagSet
.
StringVar
(
&
analyse
,
"a"
,
""
,
""
)
flagSet
.
StringVar
(
&
analyse
,
"analyse"
,
""
,
""
)
flagSet
.
IntVar
(
&
vari
.
Length
,
"W"
,
0
,
""
)
flagSet
.
IntVar
(
&
vari
.
Length
,
"width"
,
0
,
""
)
flagSet
.
StringVar
(
&
vari
.
LeftPad
,
"L"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
LeftPad
,
"leftPad"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
RightPad
,
"R"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
RightPad
,
"rightPad"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
Ip
,
"b"
,
""
,
""
)
flagSet
.
StringVar
(
&
vari
.
Ip
,
"bind"
,
""
,
""
)
flagSet
.
IntVar
(
&
vari
.
Port
,
"p"
,
0
,
""
)
flagSet
.
IntVar
(
&
vari
.
Port
,
"port"
,
0
,
""
)
flagSet
.
StringVar
(
&
root
,
"
r
"
,
""
,
""
)
flagSet
.
StringVar
(
&
root
,
"
R
"
,
""
,
""
)
flagSet
.
StringVar
(
&
root
,
"root"
,
""
,
""
)
flagSet
.
BoolVar
(
&
example
,
"e"
,
false
,
""
)
...
...
@@ -137,7 +128,7 @@ func main() {
service
.
ViewRes
(
viewRes
)
return
}
else
if
md5
!=
""
{
service
.
AddMd5
(
md5
,
salt
)
service
.
AddMd5
(
md5
)
return
}
else
if
analyse
!=
""
{
gen
.
Analyse
(
output
,
fields
,
analyse
,
defaultFile
)
...
...
@@ -203,8 +194,7 @@ func StartServer() {
}
func
DataHandler
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
root
,
defaultFile
,
configFile
,
count
,
fields
,
vari
.
HeadSep
,
vari
.
Length
,
vari
.
LeftPad
,
vari
.
RightPad
,
root
,
defaultFile
,
configFile
,
count
,
fields
,
vari
.
HeadSep
,
format
,
table
=
service
.
ParseRequestParams
(
req
)
vari
.
RunMode
=
constant
.
RunModeServerRequest
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录