Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
ab9ea07a
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 搜索 >>
提交
ab9ea07a
编写于
5月 15, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new definition format
上级
b89db667
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
63 addition
and
37 deletion
+63
-37
src/action/generator.go
src/action/generator.go
+3
-5
src/gen/definition.go
src/gen/definition.go
+41
-13
src/gen/generator.go
src/gen/generator.go
+1
-1
src/gen/text.go
src/gen/text.go
+3
-2
src/utils/config/config.go
src/utils/config/config.go
+7
-6
src/utils/const/const.go
src/utils/const/const.go
+0
-3
src/utils/file/file.go
src/utils/file/file.go
+2
-2
src/utils/vari/vari.go
src/utils/vari/vari.go
+5
-4
xdoc/apachelog.yaml
xdoc/apachelog.yaml
+1
-1
未找到文件。
src/action/generator.go
浏览文件 @
ab9ea07a
...
...
@@ -6,9 +6,9 @@ import (
"fmt"
"github.com/easysoft/zendata/src/gen"
"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"
"os"
"path/filepath"
"strconv"
...
...
@@ -18,13 +18,11 @@ import (
func
Generate
(
def
string
,
total
int
,
fieldsToExportStr
string
,
out
string
,
format
string
,
table
string
)
{
startTime
:=
time
.
Now
()
.
Unix
()
vari
.
InputDir
=
filepath
.
Dir
(
def
)
+
string
(
os
.
PathSeparator
)
fieldsToExport
:=
strings
.
Split
(
fieldsToExportStr
,
","
)
constant
.
InputDir
=
filepath
.
Dir
(
def
)
+
string
(
os
.
PathSeparator
)
referRangeFields
,
referInstFields
:=
gen
.
LoadDefinitionFromFile
(
def
,
fieldsToExport
)
// init constant.RootDef
gen
.
LoadReferRes
(
referRangeFields
,
referInstFields
)
// init const.ResMap
gen
.
LoadRootDef
(
def
,
fieldsToExport
)
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
total
,
fieldsToExport
)
content
:=
Print
(
rows
,
format
,
table
,
colTypes
,
fieldsToExport
)
...
...
src/gen/definition.go
浏览文件 @
ab9ea07a
...
...
@@ -7,10 +7,11 @@ import (
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strings"
)
func
Load
DefinitionFromFile
(
file
string
,
fieldsToExport
[]
string
)
([]
model
.
ClsRange
,
[]
model
.
ClsInst
)
{
func
Load
RootDef
(
file
string
,
fieldsToExport
[]
string
)
([]
model
.
ClsRange
,
[]
model
.
ClsInst
)
{
referRangeFields
:=
make
([]
model
.
ClsRange
,
0
)
referInstFields
:=
make
([]
model
.
ClsInst
,
0
)
...
...
@@ -27,27 +28,54 @@ func LoadDefinitionFromFile(file string, fieldsToExport []string) ([]model.ClsRa
return
referRangeFields
,
referInstFields
}
if
strings
.
Index
(
file
,
"def"
)
!=
0
&&
constant
.
RootDef
.
Title
==
""
{
// only add the fields in first level yaml file
constant
.
RootDef
=
def
}
constant
.
RootDef
=
def
//constant.ResMap =
for
_
,
field
:=
range
def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
// TODO: dealwith referRangeFields and referInstFields for constant.ResMap
if
field
.
From
!=
""
{
if
field
.
Select
!=
""
{
// excel
}
else
if
field
.
Use
!=
""
{
// range or instance format
//referFile, referType := getReferPath(field.From)
// init const.ResMap
}
}
// TODO:
}
return
referRangeFields
,
referInstFields
}
func
LoadReferRes
([]
model
.
ClsRange
,
[]
model
.
ClsInst
)
{
// init const.ResMap
func
getReferPath
(
from
string
)
(
string
,
string
,
string
)
{
referFile
:=
""
referType
:=
""
tableName
:=
""
sep
:=
string
(
os
.
PathSeparator
)
index
:=
strings
.
LastIndex
(
from
,
".yaml"
)
if
index
>
-
1
{
// system.nubmer.yaml
left
:=
from
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
sep
)
//for _, field := range def.Fields {
// fieldValue := model.FieldValue{}
// // TODO: 生成fieldValue
// constant.ResMap[field.Field] = fieldValue // add to a map
//}
}
referFile
=
left
+
".yaml"
}
else
{
// system.address.china
index
=
strings
.
LastIndex
(
from
,
"."
)
left
:=
from
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
sep
)
referFile
=
left
+
".xlsx"
tableName
=
from
[
index
:
]
}
if
strings
.
Index
(
referFile
,
"system"
)
>
-
1
{
referFile
=
constant
.
ResDir
+
referFile
}
return
referFile
,
referType
,
tableName
}
\ No newline at end of file
src/gen/generator.go
浏览文件 @
ab9ea07a
...
...
@@ -86,7 +86,7 @@ func GenerateForField(field *model.DefField, total int) []string {
}
else
if
field
.
From
!=
""
&&
field
.
Range
!=
""
{
// refer to yaml file
if
field
.
Range
!=
""
{
// specific custom file
//Load
DefinitionFromFile
(constant.InputDir + field.Range)
//Load
RootDef
(constant.InputDir + field.Range)
}
//referField := constant.ResMap[field.Field]
...
...
src/gen/text.go
浏览文件 @
ab9ea07a
...
...
@@ -4,6 +4,7 @@ import (
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"io/ioutil"
"os"
"strconv"
...
...
@@ -18,9 +19,9 @@ func GenerateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldV
stepStr
:=
"1"
if
len
(
sectionArr
)
==
2
{
stepStr
=
sectionArr
[
1
]
}
// read from
fil
e
// read frome
list
:=
make
([]
string
,
0
)
relaPath
:=
constant
.
InputDir
+
file
relaPath
:=
vari
.
InputDir
+
file
content
,
err
:=
ioutil
.
ReadFile
(
relaPath
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
relaPath
+
", try to use global config"
)
...
...
src/utils/config/config.go
浏览文件 @
ab9ea07a
...
...
@@ -18,10 +18,11 @@ import (
)
func
InitConfig
()
{
vari
.
ZDataDir
=
fileUtils
.
GetZTFDir
()
vari
.
WorkDir
=
fileUtils
.
GetExeDir
()
CheckConfigPermission
()
constant
.
ConfigFile
=
vari
.
ZData
Dir
+
constant
.
ConfigFile
constant
.
ConfigFile
=
vari
.
Work
Dir
+
constant
.
ConfigFile
vari
.
Config
=
getInst
()
InitScreenSize
()
...
...
@@ -36,7 +37,7 @@ func InitScreenSize() {
}
func
SaveConfig
(
conf
model
.
Config
)
error
{
fileUtils
.
MkDirIfNeeded
(
fileUtils
.
Get
ZTF
Dir
()
+
"def"
)
fileUtils
.
MkDirIfNeeded
(
fileUtils
.
Get
Exe
Dir
()
+
"def"
)
conf
.
Version
=
constant
.
ConfigVer
...
...
@@ -103,12 +104,12 @@ func getInst() model.Config {
}
func
CheckConfigPermission
()
{
//err := syscall.Access(vari.
ZData
Dir, syscall.O_RDWR)
//err := syscall.Access(vari.
Work
Dir, syscall.O_RDWR)
err
:=
fileUtils
.
MkDirIfNeeded
(
vari
.
ZData
Dir
+
"def"
)
err
:=
fileUtils
.
MkDirIfNeeded
(
vari
.
Work
Dir
+
"def"
)
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
fmt
.
Sprintf
(
"Permission denied to open %s for write. Please change work dir."
,
vari
.
ZData
Dir
),
color
.
FgRed
)
fmt
.
Sprintf
(
"Permission denied to open %s for write. Please change work dir."
,
vari
.
Work
Dir
),
color
.
FgRed
)
os
.
Exit
(
0
)
}
}
...
...
src/utils/const/const.go
浏览文件 @
ab9ea07a
...
...
@@ -27,9 +27,6 @@ var (
MaxNumb
=
100000
// max number in array
WorkDir
string
=
""
InputDir
string
=
""
RootDef
model
.
DefData
=
model
.
DefData
{}
ResMap
map
[
string
]
model
.
FieldValue
=
map
[
string
]
model
.
FieldValue
{}
...
...
src/utils/file/file.go
浏览文件 @
ab9ea07a
...
...
@@ -133,7 +133,7 @@ func ReadResData(path string) string {
return
jsonStr
}
func
Get
ZTF
Dir
()
string
{
// where ztf command in
func
Get
Exe
Dir
()
string
{
// where ztf command in
var
dir
string
arg1
:=
strings
.
ToLower
(
os
.
Args
[
0
])
...
...
@@ -155,7 +155,7 @@ func GetZTFDir() string { // where ztf command in
}
func
GetLogDir
()
string
{
path
:=
vari
.
ZData
Dir
+
constant
.
LogDir
path
:=
vari
.
Work
Dir
+
constant
.
LogDir
dir
,
_
:=
ioutil
.
ReadDir
(
path
)
...
...
src/utils/vari/vari.go
浏览文件 @
ab9ea07a
...
...
@@ -8,10 +8,11 @@ import (
var
(
Config
=
model
.
Config
{}
RunMode
constant
.
RunMode
ZDataDir
string
LogDir
string
ScreenWidth
int
RunMode
constant
.
RunMode
WorkDir
string
InputDir
string
LogDir
string
ScreenWidth
int
ScreenHeight
int
RequestType
string
...
...
xdoc/apachelog.yaml
浏览文件 @
ab9ea07a
...
...
@@ -37,7 +37,7 @@ fields:
-
field
:
field6
note
:
自定义的数据类型。可以通过@tag的方式对数据进行筛选。
from
:
system.nubmer.yaml
rang
e
:
small,large
us
e
:
small,large
-
field
:
field 7
note
:
自定义的数据类型,包含子字段。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录