Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
009be4f2
Z
zendata
项目概览
易企天创
/
zendata
11 个月 前同步成功
通知
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 搜索 >>
提交
009be4f2
编写于
11月 18, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
load config yaml to db
上级
3dde5f49
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
45 addition
and
33 deletion
+45
-33
src/gen/definition.go
src/gen/definition.go
+2
-25
src/gen/res.go
src/gen/res.go
+4
-4
src/model/model.go
src/model/model.go
+3
-3
src/server/service/config.go
src/server/service/config.go
+13
-1
src/utils/string/string.go
src/utils/string/string.go
+23
-0
未找到文件。
src/gen/definition.go
浏览文件 @
009be4f2
...
...
@@ -26,7 +26,7 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
}
defaultContent
,
err
:=
ioutil
.
ReadFile
(
pathDefaultFile
)
defaultContent
=
ReplaceSpecialChars
(
defaultContent
)
defaultContent
=
stringUtils
.
ReplaceSpecialChars
(
defaultContent
)
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
pathDefaultFile
),
color
.
FgCyan
)
return
defaultDef
...
...
@@ -45,7 +45,7 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
pathConfigFile
)
yamlContent
=
ReplaceSpecialChars
(
yamlContent
)
yamlContent
=
stringUtils
.
ReplaceSpecialChars
(
yamlContent
)
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
pathConfigFile
),
color
.
FgCyan
)
return
configDef
...
...
@@ -227,26 +227,3 @@ func CopyField(child model.DefField, parent *model.DefField) {
}
}
func
ReplaceSpecialChars
(
bytes
[]
byte
)
[]
byte
{
str
:=
string
(
bytes
)
inRanges
:=
false
// for ranges yaml only
ret
:=
""
for
_
,
line
:=
range
strings
.
Split
(
str
,
"
\n
"
)
{
if
strings
.
Index
(
strings
.
TrimSpace
(
line
),
"ranges"
)
==
0
{
inRanges
=
true
}
else
if
len
(
line
)
>
0
&&
string
(
line
[
0
])
!=
" "
{
// not begin with space, ranges end
inRanges
=
false
}
if
strings
.
Index
(
strings
.
TrimSpace
(
line
),
"range"
)
==
0
||
inRanges
{
line
=
strings
.
ReplaceAll
(
line
,
"["
,
string
(
constant
.
LeftBrackets
))
line
=
strings
.
ReplaceAll
(
line
,
"]"
,
string
(
constant
.
RightBrackets
))
}
ret
+=
line
+
"
\n
"
}
return
[]
byte
(
ret
)
}
src/gen/res.go
浏览文件 @
009be4f2
...
...
@@ -120,7 +120,7 @@ func getResFromYaml(resFile string) (valueMap map[string][]string, resName strin
}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
resFile
)
yamlContent
=
ReplaceSpecialChars
(
yamlContent
)
yamlContent
=
stringUtils
.
ReplaceSpecialChars
(
yamlContent
)
if
err
!=
nil
{
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
resFile
))
...
...
@@ -141,7 +141,7 @@ func getResFromYaml(resFile string) (valueMap map[string][]string, resName strin
}
else
{
configRes
:=
model
.
DefField
{}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
configRes
)
if
err
==
nil
{
// config
if
err
==
nil
{
// config
valueMap
=
getResForConfig
(
configRes
)
resName
=
configRes
.
Field
}
...
...
@@ -226,7 +226,7 @@ func getreferencedRangeOrInstant(inst model.DefField) (referencedRanges model.Re
resFile
,
_
,
_
:=
fileUtils
.
GetResProp
(
inst
.
From
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
resFile
)
yamlContent
=
ReplaceSpecialChars
(
yamlContent
)
yamlContent
=
stringUtils
.
ReplaceSpecialChars
(
yamlContent
)
if
err
!=
nil
{
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
resFile
))
return
...
...
@@ -280,4 +280,4 @@ func getResForConfig(configRes model.DefField) map[string][]string {
groupedValue
[
"all"
]
=
GenerateForField
(
&
configRes
,
false
)
return
groupedValue
}
\ No newline at end of file
}
src/model/model.go
浏览文件 @
009be4f2
...
...
@@ -243,9 +243,6 @@ type ZdConfig struct {
Name
string
`gorm:"column:name" json:"name"`
Desc
string
`gorm:"column:desc" json:"desc"`
Path
string
`gorm:"column:path" json:"path" yaml:"-"`
Yaml
string
`gorm:"yaml" json:"yaml"`
Folder
string
`gorm:"-" json:"folder" yaml:"-"`
Field
string
`gorm:"column:field" json:"field"`
Note
string
`gorm:"column:note" json:"note"`
...
...
@@ -254,6 +251,9 @@ type ZdConfig struct {
Loop
string
`gorm:"column:loop" json:"loop"`
Loopfix
string
`gorm:"column:loopfix" json:"loopfix"`
Format
string
`gorm:"column:format" json:"format"`
Yaml
string
`gorm:"yaml" json:"yaml"`
Folder
string
`gorm:"-" json:"folder" yaml:"-"`
}
func
(
*
ZdConfig
)
TableName
()
string
{
return
constant
.
TablePrefix
+
"config"
...
...
src/server/service/config.go
浏览文件 @
009be4f2
...
...
@@ -5,6 +5,8 @@ import (
"github.com/easysoft/zendata/src/server/repo"
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v3"
"io/ioutil"
)
type
ConfigService
struct
{
...
...
@@ -55,7 +57,17 @@ func (s *ConfigService) saveResToDB(config []model.ResFile, list []*model.ZdConf
for
_
,
item
:=
range
config
{
if
!
stringUtils
.
FindInArrBool
(
item
.
Path
,
names
)
{
config
:=
model
.
ZdConfig
{
Title
:
item
.
Title
,
Name
:
item
.
Name
,
Desc
:
item
.
Desc
,
Field
:
item
.
Title
,
Path
:
item
.
Path
,
Note
:
item
.
Desc
}
content
,
_
:=
ioutil
.
ReadFile
(
item
.
Path
)
yamlContent
:=
stringUtils
.
ReplaceSpecialChars
(
content
)
config
:=
model
.
ZdConfig
{}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
config
)
config
.
Title
=
item
.
Title
config
.
Name
=
item
.
Name
config
.
Desc
=
item
.
Desc
config
.
Path
=
item
.
Path
config
.
Field
=
item
.
Title
config
.
Note
=
item
.
Desc
s
.
configRepo
.
Save
(
&
config
)
}
}
...
...
src/utils/string/string.go
浏览文件 @
009be4f2
...
...
@@ -245,3 +245,26 @@ func UrlEncode(str string) (ret string) {
return
}
func
ReplaceSpecialChars
(
bytes
[]
byte
)
[]
byte
{
str
:=
string
(
bytes
)
inRanges
:=
false
// for ranges yaml only
ret
:=
""
for
_
,
line
:=
range
strings
.
Split
(
str
,
"
\n
"
)
{
if
strings
.
Index
(
strings
.
TrimSpace
(
line
),
"ranges"
)
==
0
{
inRanges
=
true
}
else
if
len
(
line
)
>
0
&&
string
(
line
[
0
])
!=
" "
{
// not begin with space, ranges end
inRanges
=
false
}
if
strings
.
Index
(
strings
.
TrimSpace
(
line
),
"range"
)
==
0
||
inRanges
{
line
=
strings
.
ReplaceAll
(
line
,
"["
,
string
(
constant
.
LeftBrackets
))
line
=
strings
.
ReplaceAll
(
line
,
"]"
,
string
(
constant
.
RightBrackets
))
}
ret
+=
line
+
"
\n
"
}
return
[]
byte
(
ret
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录