Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
5c49b2ca
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 搜索 >>
提交
5c49b2ca
编写于
8月 18, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close task#7690
上级
12b71395
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
74 addition
and
50 deletion
+74
-50
data/.cache/.data.db
data/.cache/.data.db
+0
-0
data/chinese/words/v1.xlsx
data/chinese/words/v1.xlsx
+0
-0
demo/chinese.yaml
demo/chinese.yaml
+22
-0
res/en/sample.yaml
res/en/sample.yaml
+1
-1
res/zh/sample.yaml
res/zh/sample.yaml
+1
-1
src/action/generator.go
src/action/generator.go
+8
-39
src/gen/decode.go
src/gen/decode.go
+10
-4
src/utils/log/print.go
src/utils/log/print.go
+28
-0
src/zd.go
src/zd.go
+4
-5
未找到文件。
data/.cache/.data.db
浏览文件 @
5c49b2ca
无法预览此类型文件
data/chinese/words/v1.xlsx
0 → 100644
浏览文件 @
5c49b2ca
文件已添加
demo/chinese.yaml
0 → 100644
浏览文件 @
5c49b2ca
title
:
zendata数据配置语法说明
desc
:
author
:
zentao
version
:
1.0
type
:
lines
# lines|media|binary|article
fields
:
-
field
:
subject
from
:
chinese.words.v1.cn
select
:
word
where
:
ming='y' and dong="n"
-
field
:
verb
from
:
chinese.words.v1.cn
select
:
word
where
:
dong='y'
-
field
:
object
from
:
chinese.words.v1.cn
select
:
word
where
:
ming='y'
res/en/sample.yaml
浏览文件 @
5c49b2ca
...
...
@@ -89,7 +89,7 @@ fields:
postfix
:
"
\t
"
-
field
:
field_repeat
# Use {} to define repeated elements.
range
:
u-1{3},[u2,u3]{2},[1-3]{3}
# u-1,u-1,u-1,u2,u2,u
ser3,user
3,1,1,1,2,2,2,3,3,3
range
:
u-1{3},[u2,u3]{2},[1-3]{3}
# u-1,u-1,u-1,u2,u2,u
3,u
3,1,1,1,2,2,2,3,3,3
postfix
:
"
\t
"
-
field
:
field_format
# Output as formatted strings.
...
...
res/zh/sample.yaml
浏览文件 @
5c49b2ca
...
...
@@ -89,7 +89,7 @@ fields:
postfix
:
"
\t
"
-
field
:
field_repeat
# 通过{}定义重复的元素。
range
:
user-1{3},[user2,user3]{2}
# user-1,user-1,user-1,user2,user
3,user2
,user3
range
:
user-1{3},[user2,user3]{2}
# user-1,user-1,user-1,user2,user
2,user3
,user3
postfix
:
"
\t
"
-
field
:
field_format
# 通过格式化字符串输出。
...
...
src/action/generator.go
浏览文件 @
5c49b2ca
...
...
@@ -9,20 +9,12 @@ import (
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"github.com/mattn/go-runewidth"
"net/http"
"os"
"regexp"
"strings"
"time"
)
var
(
FileWriter
*
os
.
File
HttpWriter
http
.
ResponseWriter
)
func
Generate
(
defaultFile
string
,
configFile
string
,
total
int
,
fieldsToExportStr
string
,
out
string
,
format
string
,
table
string
)
{
startTime
:=
time
.
Now
()
.
Unix
()
...
...
@@ -92,13 +84,13 @@ func Print(rows [][]string, format string, table string, colIsNumArr []bool, fie
}
if
format
==
constant
.
FormatText
{
p
rintLine
(
lineForText
)
logUtils
.
P
rintLine
(
lineForText
)
}
else
if
format
==
constant
.
FormatSql
{
p
rintLine
(
genSqlLine
(
strings
.
Join
(
valuesForSql
,
", "
),
i
,
len
(
rows
)))
logUtils
.
P
rintLine
(
genSqlLine
(
strings
.
Join
(
valuesForSql
,
", "
),
i
,
len
(
rows
)))
}
else
if
format
==
constant
.
FormatJson
{
p
rintLine
(
genJsonLine
(
i
,
row
,
len
(
rows
),
fields
))
logUtils
.
P
rintLine
(
genJsonLine
(
i
,
row
,
len
(
rows
),
fields
))
}
else
if
format
==
constant
.
FormatXml
{
p
rintLine
(
getXmlLine
(
i
,
rowMap
,
len
(
rows
)))
logUtils
.
P
rintLine
(
getXmlLine
(
i
,
rowMap
,
len
(
rows
)))
}
}
}
...
...
@@ -115,21 +107,21 @@ func printTextHeader(fields []string) {
}
}
p
rintLine
(
headerLine
)
logUtils
.
P
rintLine
(
headerLine
)
}
func
printSqlHeader
(
fields
[]
string
,
table
string
)
{
fieldNames
:=
make
([]
string
,
0
)
for
_
,
f
:=
range
fields
{
fieldNames
=
append
(
fieldNames
,
"`"
+
f
+
"`"
)
}
p
rintLine
(
fmt
.
Sprintf
(
"INSERT INTO %s(%s)"
,
table
,
strings
.
Join
(
fieldNames
,
", "
)))
logUtils
.
P
rintLine
(
fmt
.
Sprintf
(
"INSERT INTO %s(%s)"
,
table
,
strings
.
Join
(
fieldNames
,
", "
)))
}
func
printJsonHeader
()
{
p
rintLine
(
"["
)
logUtils
.
P
rintLine
(
"["
)
}
func
printXmlHeader
(
fields
[]
string
,
table
string
)
{
p
rintLine
(
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
<testdata>
\n
<title>Test Data</title>"
)
logUtils
.
P
rintLine
(
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
<testdata>
\n
<title>Test Data</title>"
)
}
func
RowToJson
(
cols
[]
string
,
fieldsToExport
[]
string
)
string
{
...
...
@@ -248,27 +240,4 @@ func getValForPlaceholder(placeholderStr string, count int) []string {
}
return
strs
}
func
PrintErrMsg
(
msg
string
)
{
logUtils
.
PrintToWithColor
(
msg
,
color
.
FgCyan
)
}
func
printLine
(
line
string
)
{
if
FileWriter
!=
nil
{
PrintToFile
(
line
)
}
else
if
vari
.
RunMode
==
constant
.
RunModeServerRequest
{
PrintToHttp
(
line
)
}
else
{
PrintToScreen
(
line
)
}
}
func
PrintToFile
(
line
string
)
{
fmt
.
Fprintln
(
FileWriter
,
line
)
}
func
PrintToHttp
(
line
string
)
{
fmt
.
Fprintln
(
HttpWriter
,
line
)
}
func
PrintToScreen
(
line
string
)
{
fmt
.
Println
(
line
)
}
\ No newline at end of file
src/gen/decode.go
浏览文件 @
5c49b2ca
...
...
@@ -3,11 +3,12 @@ package gen
import
(
"encoding/json"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
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"
"os"
"path/filepath"
"strings"
)
...
...
@@ -16,6 +17,13 @@ const (
)
func
Decode
(
defaultFile
,
configFile
,
fieldsToExportStr
,
input
,
output
string
)
{
if
output
!=
""
{
fileUtils
.
MkDirIfNeeded
(
filepath
.
Dir
(
output
))
fileUtils
.
RemoveExist
(
output
)
logUtils
.
FileWriter
,
_
=
os
.
OpenFile
(
output
,
os
.
O_RDWR
|
os
.
O_CREATE
,
0777
)
defer
logUtils
.
FileWriter
.
Close
()
}
vari
.
DefaultDir
=
fileUtils
.
GetAbsDir
(
defaultFile
)
vari
.
ConfigDir
=
fileUtils
.
GetAbsDir
(
configFile
)
...
...
@@ -37,9 +45,7 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) {
vari
.
JsonResp
=
string
(
jsonObj
)
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"analyse_success"
,
output
))
if
vari
.
RunMode
!=
constant
.
RunModeServerRequest
{
fileUtils
.
WriteFile
(
output
,
vari
.
JsonResp
)
}
logUtils
.
PrintLine
(
vari
.
JsonResp
)
}
func
LinesToMap
(
str
string
,
fieldsToExport
[]
string
,
ret
*
[]
map
[
string
]
interface
{})
{
...
...
src/utils/log/print.go
浏览文件 @
5c49b2ca
...
...
@@ -3,9 +3,11 @@ package logUtils
import
(
"fmt"
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"net/http"
"os"
"regexp"
"strings"
...
...
@@ -14,6 +16,9 @@ import (
var
(
exampleFile
=
fmt
.
Sprintf
(
"res%sen%ssample.yaml"
,
string
(
os
.
PathSeparator
),
string
(
os
.
PathSeparator
))
usageFile
=
fmt
.
Sprintf
(
"res%sen%susage.txt"
,
string
(
os
.
PathSeparator
),
string
(
os
.
PathSeparator
))
FileWriter
*
os
.
File
HttpWriter
http
.
ResponseWriter
)
func
PrintExample
()
{
...
...
@@ -69,3 +74,26 @@ func PrintToWithColor(msg string, attr color.Attribute) {
color
.
New
(
attr
)
.
Fprintf
(
output
,
msg
+
"
\n
"
)
}
}
func
PrintErrMsg
(
msg
string
)
{
PrintToWithColor
(
msg
,
color
.
FgCyan
)
}
func
PrintLine
(
line
string
)
{
if
FileWriter
!=
nil
{
PrintToFile
(
line
)
}
else
if
vari
.
RunMode
==
constant
.
RunModeServerRequest
{
PrintToHttp
(
line
)
}
else
{
PrintToScreen
(
line
)
}
}
func
PrintToFile
(
line
string
)
{
fmt
.
Fprintln
(
FileWriter
,
line
)
}
func
PrintToHttp
(
line
string
)
{
fmt
.
Fprintln
(
HttpWriter
,
line
)
}
func
PrintToScreen
(
line
string
)
{
fmt
.
Println
(
line
)
}
src/zd.go
浏览文件 @
5c49b2ca
...
...
@@ -190,8 +190,8 @@ func toGen() {
if
output
!=
""
{
fileUtils
.
MkDirIfNeeded
(
filepath
.
Dir
(
output
))
fileUtils
.
RemoveExist
(
output
)
action
.
FileWriter
,
_
=
os
.
OpenFile
(
output
,
os
.
O_RDWR
|
os
.
O_CREATE
,
0777
)
defer
action
.
FileWriter
.
Close
()
logUtils
.
FileWriter
,
_
=
os
.
OpenFile
(
output
,
os
.
O_RDWR
|
os
.
O_CREATE
,
0777
)
defer
logUtils
.
FileWriter
.
Close
()
ext
:=
strings
.
ToLower
(
path
.
Ext
(
output
))
if
len
(
ext
)
>
1
{
...
...
@@ -203,7 +203,7 @@ func toGen() {
}
if
format
==
constant
.
FormatSql
&&
table
==
""
{
action
.
PrintErrMsg
(
i118Utils
.
I118Prt
.
Sprintf
(
"miss_table_name"
))
logUtils
.
PrintErrMsg
(
i118Utils
.
I118Prt
.
Sprintf
(
"miss_table_name"
))
return
}
...
...
@@ -232,14 +232,13 @@ func StartServer() {
}
func
DataHandler
(
writer
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
action
.
HttpWriter
=
writer
logUtils
.
HttpWriter
=
writer
defaultFile
,
configFile
,
fields
,
count
,
format
,
table
,
decode
,
input
,
output
=
service
.
ParseRequestParams
(
req
)
if
decode
{
gen
.
Decode
(
defaultFile
,
configFile
,
fields
,
input
,
output
)
fmt
.
Fprintln
(
writer
,
vari
.
JsonResp
)
}
else
if
defaultFile
!=
""
||
configFile
!=
""
{
vari
.
RunMode
=
constant
.
RunModeServerRequest
logUtils
.
PrintToWithoutNewLine
(
i118Utils
.
I118Prt
.
Sprintf
(
"server_request"
,
req
.
Method
,
req
.
URL
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录