Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
d4766f31
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 搜索 >>
提交
d4766f31
编写于
7月 22, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support instance use another instance
上级
56a1dc62
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
86 addition
and
12 deletion
+86
-12
data/system/ip/private.yaml
data/system/ip/private.yaml
+15
-0
data/system/ip/v1.yaml
data/system/ip/v1.yaml
+15
-2
demo/test.yaml
demo/test.yaml
+6
-0
src/gen/generator.go
src/gen/generator.go
+4
-0
src/gen/res.go
src/gen/res.go
+46
-10
未找到文件。
data/system/ip/private.yaml
0 → 100644
浏览文件 @
d4766f31
title
:
私有IP
desc
:
author
:
zentao
version
:
1.0
field
:
privateIP
instances
:
-
instance
:
all
fields
:
-
field
:
part
from
:
system.ip.v1.yaml
use
:
privateA, privateB, privateC
prefix
:
"
"
postfix
:
"
/24"
data/system/ip/v1.yaml
浏览文件 @
d4766f31
...
...
@@ -23,7 +23,20 @@ instances:
range
:
16-31
postfix
:
.
-
field
:
part3
range
:
0-25
5
range
:
0-25
4
postfix
:
.
-
field
:
part4
range
:
0-255
range
:
1-254
-
instance
:
privateA
note
:
A类IP地址
prefix
:
10.
fields
:
-
field
:
part2
range
:
0-254
postfix
:
.
-
field
:
part3
range
:
0-254
postfix
:
.
-
field
:
part4
range
:
1-254
\ No newline at end of file
demo/test.yaml
浏览文件 @
d4766f31
...
...
@@ -19,3 +19,9 @@ fields:
-
field
:
field_loop
# 引用default.xml里的自循环的字段
prefix
:
"
["
# 复写前缀
postfix
:
"
]"
# 特殊字符加引号,否则无法解析
-
field
:
field_nested_inst
# 引用的instance使用多层嵌套的use定义
from
:
system.ip.private.yaml
# 引用data/system/ip/v1.yaml
use
:
all
# 使用该文件中定义的privateC和privateB两个实例。
prefix
:
"
["
# 复写前缀
postfix
:
"
]"
# 特殊字符加引号,否则无法解析
src/gen/generator.go
浏览文件 @
d4766f31
...
...
@@ -79,6 +79,10 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
}
else
if
field
.
From
!=
""
{
// refer to res
if
field
.
Use
!=
""
{
// refer to instance
if
field
.
Use
==
"privateIP"
{
fmt
.
Println
(
""
)
}
groupValues
:=
vari
.
Res
[
field
.
From
]
groups
:=
strings
.
Split
(
field
.
Use
,
","
)
for
_
,
group
:=
range
groups
{
...
...
src/gen/res.go
浏览文件 @
d4766f31
...
...
@@ -147,23 +147,59 @@ func getResForInstances(insts model.ResInsts) map[string][]string {
groupedValue
:=
map
[
string
][]
string
{}
for
_
,
inst
:=
range
insts
.
Instances
{
group
:=
inst
.
Instance
for
_
,
instField
:=
range
inst
.
Fields
{
// prepare referred parent instances if needed
if
instField
.
Use
!=
""
{
// refer to another instance
parent
:=
getRootInstant
(
instField
)
groupedValueParent
:=
map
[
string
][]
string
{}
for
_
,
child
:=
range
parent
.
Instances
{
field
:=
convertInstantToField
(
parent
,
child
)
// gen values
group
:=
child
.
Instance
groupedValueParent
[
group
]
=
GenerateForField
(
&
field
,
constant
.
Total
,
false
)
}
vari
.
Res
[
instField
.
From
]
=
groupedValueParent
}
}
// convert instant field to standard field
tempField
:=
model
.
DefField
{}
tempField
.
Field
=
insts
.
Field
field
:=
convertInstantToField
(
insts
,
inst
)
child
:=
model
.
DefField
{}
child
.
Field
=
inst
.
Instance
// gen values
group
:=
inst
.
Instance
groupedValue
[
group
]
=
GenerateForField
(
&
field
,
constant
.
Total
,
false
)
}
copier
.
Copy
(
&
child
,
inst
)
return
groupedValue
}
tempField
.
Fields
=
append
(
tempField
.
Fields
,
child
)
func
getRootInstant
(
inst
model
.
DefField
)
(
parentInsts
model
.
ResInsts
)
{
resFile
,
_
:=
getResProp
(
inst
.
From
)
groupedValue
[
group
]
=
GenerateForField
(
&
tempField
,
constant
.
Total
,
false
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
resFile
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
resFile
))
return
}
return
groupedValue
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
parentInsts
)
if
err
==
nil
&&
parentInsts
.
Instances
!=
nil
&&
len
(
parentInsts
.
Instances
)
>
0
{
// instances
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_parse_file"
,
resFile
))
}
return
}
func
convertInstantToField
(
insts
model
.
ResInsts
,
inst
model
.
ResInst
)
(
field
model
.
DefField
)
{
field
.
Field
=
insts
.
Field
child
:=
model
.
DefField
{}
child
.
Field
=
inst
.
Instance
copier
.
Copy
(
&
child
,
inst
)
field
.
Fields
=
append
(
field
.
Fields
,
child
)
return
field
}
func
getResForRanges
(
ranges
model
.
ResRanges
)
map
[
string
][]
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录