Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
f063edb1
Z
zendata
项目概览
易企天创
/
zendata
9 个月 前同步成功
通知
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 搜索 >>
提交
f063edb1
编写于
3月 10, 2021
作者:
陈
陈琦
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issues
上级
371b6d26
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
248 addition
and
126 deletion
+248
-126
.gitignore
.gitignore
+3
-1
demo/01_range.yaml
demo/01_range.yaml
+1
-3
demo/20_override.yaml
demo/20_override.yaml
+0
-0
src/action/sql.go
src/action/sql.go
+3
-3
src/gen/charVal.go
src/gen/charVal.go
+4
-4
src/gen/decode.go
src/gen/decode.go
+11
-5
src/gen/excel.go
src/gen/excel.go
+1
-1
src/gen/floatVal.go
src/gen/floatVal.go
+16
-16
src/gen/helper/rand.go
src/gen/helper/rand.go
+14
-8
src/gen/intVal.go
src/gen/intVal.go
+78
-32
src/gen/list.go
src/gen/list.go
+67
-29
src/gen/parser.go
src/gen/parser.go
+12
-5
src/gen/printer.go
src/gen/printer.go
+4
-3
src/gen/text.go
src/gen/text.go
+1
-1
src/gen/timestamp.go
src/gen/timestamp.go
+1
-1
src/model/model.go
src/model/model.go
+7
-5
src/server/repo/section.go
src/server/repo/section.go
+2
-2
src/server/service/def.go
src/server/service/def.go
+7
-4
src/server/service/instances.go
src/server/service/instances.go
+6
-3
test/test.yaml
test/test.yaml
+10
-0
未找到文件。
.gitignore
浏览文件 @
f063edb1
...
...
@@ -11,7 +11,7 @@
/nohup.out
/test/ztf/conf/
/test/ztf/log/
/demo/out
put
/
/demo/out/
/test/ztf/._config.yaml
/test/ztf/._default.yaml
/._config.yaml
...
...
@@ -23,3 +23,5 @@
/qshell.log
/log-agent/
/data/test/
/test/out/
/log-agent/
demo/01_range.yaml
浏览文件 @
f063edb1
...
...
@@ -3,6 +3,4 @@ desc: 描述
version
:
1.0
fields
:
-
field
:
first
# 字段名
range
:
1-5,
30
# 1,2,3,4,5,30,1,2,3,4,5
prefix
:
"
=="
postfix
:
"
--"
\ No newline at end of file
range
:
1-5,
30
# 1,2,3,4,5,30,1,2,3,4,5
\ No newline at end of file
demo/20_override
_18
.yaml
→
demo/20_override.yaml
浏览文件 @
f063edb1
文件已移动
src/action/sql.go
浏览文件 @
f063edb1
...
...
@@ -23,7 +23,7 @@ func ParseSql(file string, out string) {
def
.
Init
(
tableName
,
"automated export"
,
""
,
"1.0"
)
for
_
,
col
:=
range
columns
{
field
:=
model
.
FieldSimple
{}
field
:=
model
.
FieldSimple
{
Range
:
" "
}
field
.
Init
(
col
)
def
.
Fields
=
append
(
def
.
Fields
,
field
)
}
...
...
@@ -41,7 +41,7 @@ func ParseSql(file string, out string) {
}
entTime
:=
time
.
Now
()
.
Unix
()
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"generate_yaml"
,
len
(
statements
),
out
,
entTime
-
startTime
))
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"generate_yaml"
,
len
(
statements
),
out
,
entTime
-
startTime
))
}
func
getCreateStatement
(
file
string
)
map
[
string
]
string
{
...
...
@@ -85,4 +85,4 @@ func getColumnsFromCreateStatement(sent string) []string {
}
return
fieldLines
}
\ No newline at end of file
}
src/gen/charVal.go
浏览文件 @
f063edb1
...
...
@@ -5,10 +5,10 @@ import (
constant
"github.com/easysoft/zendata/src/utils/const"
)
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
int
,
rand
bool
,
repeat
int
)
[]
interface
{}
{
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
int
,
rand
bool
,
repeat
int
,
tag
string
)
[]
interface
{}
{
if
!
rand
{
return
generateByteItemsByStep
(
start
,
end
,
step
,
repeat
)
}
else
{
}
else
{
return
generateByteItemsRand
(
start
,
end
,
step
,
repeat
)
}
}
...
...
@@ -19,7 +19,7 @@ func generateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
total
:=
0
for
i
:=
0
;
true
;
{
val
:=
start
+
byte
(
int
(
i
)
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
...
...
@@ -69,4 +69,4 @@ func generateByteItemsRand(start byte, end byte, step int, repeat int) []interfa
}
return
arr
}
\ No newline at end of file
}
src/gen/decode.go
浏览文件 @
f063edb1
...
...
@@ -6,6 +6,7 @@ import (
fileUtils
"github.com/easysoft/zendata/src/utils/file"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"os"
"path/filepath"
"strings"
...
...
@@ -37,7 +38,7 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) {
data
:=
fileUtils
.
ReadFile
(
input
)
var
ret
[]
map
[
string
]
interface
{}
L
inesToMap
(
data
,
fieldsToExport
,
&
ret
)
l
inesToMap
(
data
,
fieldsToExport
,
&
ret
)
jsonObj
,
_
:=
json
.
Marshal
(
ret
)
vari
.
JsonResp
=
string
(
jsonObj
)
...
...
@@ -45,7 +46,7 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) {
logUtils
.
PrintLine
(
vari
.
JsonResp
)
}
func
L
inesToMap
(
str
string
,
fieldsToExport
[]
string
,
ret
*
[]
map
[
string
]
interface
{})
{
func
l
inesToMap
(
str
string
,
fieldsToExport
[]
string
,
ret
*
[]
map
[
string
]
interface
{})
{
start
:=
0
if
vari
.
WithHead
{
start
=
1
...
...
@@ -64,15 +65,16 @@ func LinesToMap(str string, fieldsToExport []string, ret *[]map[string]interface
}
func
decodeOneLevel
(
line
string
,
fields
[]
model
.
DefField
,
rowMap
*
map
[
string
]
interface
{})
{
left
:=
[]
rune
(
line
)
for
j
,
field
:=
range
fields
{
col
:=
""
if
field
.
Length
>
0
{
col
=
string
(
left
[
:
field
.
Length
])
left
=
left
[
field
.
Length
:
]
len
:=
field
.
Length
+
runewidth
.
StringWidth
(
field
.
Prefix
)
+
runewidth
.
StringWidth
(
field
.
Postfix
)
col
=
string
(
left
[
:
len
])
left
=
left
[
len
:
]
}
else
{
sepStr
:=
""
if
j
<
len
(
fields
)
-
1
{
...
...
@@ -94,6 +96,10 @@ func decodeOneLevel(line string, fields []model.DefField, rowMap *map[string]int
}
}
if
vari
.
Trim
{
col
=
strings
.
TrimLeft
(
col
,
field
.
Prefix
)
col
=
strings
.
TrimRight
(
col
,
field
.
Postfix
)
}
(
*
rowMap
)[
field
.
Field
]
=
col
children
:=
field
.
Fields
...
...
src/gen/excel.go
浏览文件 @
f063edb1
...
...
@@ -32,7 +32,7 @@ func GenerateFieldValuesFromExcel(filePath, sheet string, field *model.DefField)
list
,
selectCol
:=
ReadDataFromSQLite
(
*
field
,
dbName
,
sheet
)
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
1
,
false
,
1
)
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
1
,
false
,
1
,
""
)
// get data by index
index
:=
0
for
_
,
numb
:=
range
numbs
{
...
...
src/gen/floatVal.go
浏览文件 @
f063edb1
...
...
@@ -7,10 +7,10 @@ import (
"strings"
)
func
GenerateFloatItems
(
start
float64
,
end
float64
,
step
interface
{},
rand
bool
,
repeat
int
)
[]
interface
{}
{
func
GenerateFloatItems
(
start
float64
,
end
float64
,
step
interface
{},
rand
bool
,
repeat
int
,
tag
string
)
[]
interface
{}
{
if
!
rand
{
return
generateFloatItemsByStep
(
start
,
end
,
step
.
(
float64
),
repeat
)
}
else
{
}
else
{
return
generateFloatItemsRand
(
start
,
end
,
step
.
(
float64
),
repeat
)
}
}
...
...
@@ -21,8 +21,8 @@ func generateFloatItemsByStep(start float64, end float64, step float64, repeat i
total
:=
0
for
i
:=
0
;
true
;
{
val
:=
start
+
float64
(
i
)
*
step
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
val
:=
start
+
float64
(
i
)
*
step
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
...
...
@@ -54,7 +54,7 @@ func generateFloatItemsRand(start float64, end float64, step float64, repeat int
rand
=
rand
*
-
1
}
val
:=
start
+
float64
(
rand
)
*
step
val
:=
start
+
float64
(
rand
)
*
step
for
round
:=
0
;
round
<
repeat
;
round
++
{
arr
=
append
(
arr
,
val
)
...
...
@@ -109,16 +109,16 @@ func InterfaceToStr(val interface{}) string {
str
:=
"n/a"
switch
val
.
(
type
)
{
case
int64
:
str
=
strconv
.
FormatInt
(
val
.
(
int64
),
10
)
case
float64
:
precision
,
_
:=
GetPrecision
(
val
.
(
float64
),
nil
)
str
=
strconv
.
FormatFloat
(
val
.
(
float64
),
'f'
,
precision
,
64
)
case
byte
:
str
=
string
(
val
.
(
byte
))
case
string
:
str
=
val
.
(
string
)
default
:
case
int64
:
str
=
strconv
.
FormatInt
(
val
.
(
int64
),
10
)
case
float64
:
precision
,
_
:=
GetPrecision
(
val
.
(
float64
),
nil
)
str
=
strconv
.
FormatFloat
(
val
.
(
float64
),
'f'
,
precision
,
64
)
case
byte
:
str
=
string
(
val
.
(
byte
))
case
string
:
str
=
val
.
(
string
)
default
:
}
return
str
}
\ No newline at end of file
}
src/gen/helper/rand.go
浏览文件 @
f063edb1
...
...
@@ -26,7 +26,7 @@ func GetRandFromList(list []string, repeatStr string, count int) []string {
return
ret
}
func
GetRandFromRange
(
dataType
,
start
,
end
,
step
,
repeatStr
,
precisionStr
string
,
count
int
,
format
string
)
[]
string
{
func
GetRandFromRange
(
dataType
,
start
,
end
,
step
,
repeatStr
,
repeatTag
,
precisionStr
string
,
count
int
,
format
string
)
[]
string
{
repeat
,
_
:=
strconv
.
Atoi
(
repeatStr
)
precision
,
_
:=
strconv
.
Atoi
(
precisionStr
)
...
...
@@ -41,7 +41,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepInt
=
stepInt
*
-
1
}
countInRound
:=
(
endInt
-
startInt
)
/
stepInt
+
1
countInRound
:=
(
endInt
-
startInt
)
/
stepInt
+
1
for
i
:=
0
;
i
<
count
;
i
++
{
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
...
...
@@ -54,7 +54,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item
:=
strconv
.
FormatInt
(
val
,
10
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
,
0
)
if
success
{
item
=
formatVal
}
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
...
...
@@ -73,7 +75,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepInt
=
stepInt
*
-
1
}
countInRound
:=
(
int64
(
endChar
)
-
int64
(
startChar
))
/
stepInt
+
1
countInRound
:=
(
int64
(
endChar
)
-
int64
(
startChar
))
/
stepInt
+
1
for
i
:=
0
;
i
<
count
;
i
++
{
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
...
...
@@ -86,7 +88,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item
:=
string
(
val
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
,
0
)
if
success
{
item
=
formatVal
}
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
...
...
@@ -106,7 +110,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepFloat
=
stepFloat
*
-
1
}
countInRound
:=
(
endFloat
-
startFloat
)
/
stepFloat
+
1
countInRound
:=
(
endFloat
-
startFloat
)
/
stepFloat
+
1
for
i
:=
0
;
i
<
count
;
i
++
{
rand
:=
commonUtils
.
RandNum64
(
int64
(
countInRound
))
...
...
@@ -121,7 +125,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item
:=
strconv
.
FormatFloat
(
val
,
'f'
,
precision
,
64
)
if
format
!=
""
{
formatVal
,
success
:=
stringUtils
.
FormatStr
(
format
,
val
,
precision
)
if
success
{
item
=
formatVal
}
if
success
{
item
=
formatVal
}
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
...
...
@@ -134,4 +140,4 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
}
return
ret
}
\ No newline at end of file
}
src/gen/intVal.go
浏览文件 @
f063edb1
...
...
@@ -5,69 +5,115 @@ import (
constant
"github.com/easysoft/zendata/src/utils/const"
)
func
GenerateIntItems
(
start
int64
,
end
int64
,
step
interface
{},
rand
bool
,
repeat
int
)
[]
interface
{}
{
func
GenerateIntItems
(
start
int64
,
end
int64
,
step
interface
{},
rand
bool
,
repeat
int
,
repeatTag
string
)
[]
interface
{}
{
if
!
rand
{
return
generateIntItemsByStep
(
start
,
end
,
step
.
(
int
),
repeat
)
}
else
{
return
generateIntItemsRand
(
start
,
end
,
step
.
(
int
),
repeat
)
return
generateIntItemsByStep
(
start
,
end
,
step
.
(
int
),
repeat
,
repeatTag
)
}
else
{
return
generateIntItemsRand
(
start
,
end
,
step
.
(
int
),
repeat
,
repeatTag
)
}
}
func
generateIntItemsByStep
(
start
int64
,
end
int64
,
step
int
,
repeat
int
)
[]
interface
{}
{
func
generateIntItemsByStep
(
start
int64
,
end
int64
,
step
int
,
repeat
int
,
repeatTag
string
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
total
:=
0
for
i
:=
0
;
true
;
{
val
:=
start
+
int64
(
i
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
if
repeatTag
==
""
{
for
i
:=
0
;
true
;
{
val
:=
start
+
int64
(
i
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
arr
=
append
(
arr
,
val
)
for
round
:=
0
;
round
<
repeat
;
round
++
{
arr
=
append
(
arr
,
val
)
total
++
if
total
>
constant
.
MaxNumb
{
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
if
total
>=
constant
.
MaxNumb
{
break
}
i
++
}
}
else
if
repeatTag
==
"!"
{
for
round
:=
0
;
round
<
repeat
;
round
++
{
for
i
:=
0
;
true
;
{
val
:=
start
+
int64
(
i
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
arr
=
append
(
arr
,
val
)
if
total
>=
constant
.
MaxNumb
{
break
}
i
++
}
if
total
>=
constant
.
MaxNumb
{
break
if
total
>=
constant
.
MaxNumb
{
break
}
}
i
++
}
return
arr
}
func
generateIntItemsRand
(
start
int64
,
end
int64
,
step
int
,
repeat
int
)
[]
interface
{}
{
func
generateIntItemsRand
(
start
int64
,
end
int64
,
step
int
,
repeat
int
,
repeatTag
string
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
countInRound
:=
(
end
-
start
)
/
int64
(
step
)
+
1
countInRound
:=
(
end
-
start
)
/
int64
(
step
)
+
1
total
:=
0
for
i
:=
int64
(
0
);
i
<
countInRound
;
{
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
if
step
<
0
{
rand
=
rand
*
-
1
}
val
:=
start
+
rand
for
round
:=
0
;
round
<
repeat
;
round
++
{
arr
=
append
(
arr
,
val
)
if
repeatTag
==
""
{
for
i
:=
int64
(
0
);
i
<
countInRound
;
{
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
if
step
<
0
{
rand
=
rand
*
-
1
}
total
++
val
:=
start
+
rand
for
round
:=
0
;
round
<
repeat
;
round
++
{
arr
=
append
(
arr
,
val
)
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
if
total
>
constant
.
MaxNumb
{
break
}
i
++
}
}
else
if
repeatTag
==
"!"
{
for
round
:=
0
;
round
<
repeat
;
round
++
{
for
i
:=
int64
(
0
);
i
<
countInRound
;
{
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
if
step
<
0
{
rand
=
rand
*
-
1
}
val
:=
start
+
rand
arr
=
append
(
arr
,
val
)
if
total
>
constant
.
MaxNumb
{
break
if
total
>
constant
.
MaxNumb
{
break
}
i
++
}
if
total
>
constant
.
MaxNumb
{
break
}
}
i
++
}
return
arr
}
\ No newline at end of file
}
src/gen/list.go
浏览文件 @
f063edb1
...
...
@@ -50,7 +50,7 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
continue
}
descStr
,
stepStr
,
repeat
:=
ParseRangeSection
(
rangeSection
)
// parse 2
descStr
,
stepStr
,
count
,
countTag
:=
ParseRangeSection
(
rangeSection
)
// parse 2
if
strings
.
ToLower
(
stepStr
)
==
"r"
{
(
*
field
)
.
IsRand
=
true
}
...
...
@@ -59,11 +59,11 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
items
:=
make
([]
interface
{},
0
)
if
typ
==
"literal"
{
items
=
CreateValuesFromLiteral
(
field
,
desc
,
stepStr
,
repeat
)
items
=
CreateValuesFromLiteral
(
field
,
desc
,
stepStr
,
count
,
countTag
)
}
else
if
typ
==
"interval"
{
items
=
CreateValuesFromInterval
(
field
,
desc
,
stepStr
,
repeat
)
items
=
CreateValuesFromInterval
(
field
,
desc
,
stepStr
,
count
,
countTag
)
}
else
if
typ
==
"yaml"
{
// load from a yaml
items
=
CreateValuesFromYaml
(
field
,
desc
,
stepStr
,
repeat
)
items
=
CreateValuesFromYaml
(
field
,
desc
,
stepStr
,
count
,
countTag
)
field
.
ReferToAnotherYaml
=
true
}
...
...
@@ -160,7 +160,7 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
return
"string"
,
1
,
0
,
false
// is string
}
func
CreateValuesFromLiteral
(
field
*
model
.
DefField
,
desc
string
,
stepStr
string
,
repeat
int
)
(
items
[]
interface
{})
{
func
CreateValuesFromLiteral
(
field
*
model
.
DefField
,
desc
string
,
stepStr
string
,
repeat
int
,
repeatTag
string
)
(
items
[]
interface
{})
{
elemArr
:=
ParseDesc
(
desc
)
step
,
_
:=
strconv
.
Atoi
(
stepStr
)
if
step
==
0
{
...
...
@@ -170,33 +170,37 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
if
field
.
Path
!=
""
&&
stepStr
==
"r"
{
items
=
append
(
items
,
Placeholder
(
field
.
Path
))
mp
:=
placeholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
field
.
Format
)
mp
:=
placeholderMapForRandValues
(
"list"
,
elemArr
,
""
,
""
,
""
,
""
,
field
.
Format
,
repeatTag
)
vari
.
RandFieldNameToValuesMap
[
field
.
Path
]
=
mp
return
}
for
i
:=
0
;
i
<
len
(
elemArr
);
{
idx
:=
i
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
idx
=
commonUtils
.
RandNum
(
len
(
elemArr
))
// should set random here too
}
val
:=
elemArr
[
idx
]
if
repeatTag
==
""
{
for
i
:=
0
;
i
<
len
(
elemArr
);
{
idx
:=
i
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
idx
=
commonUtils
.
RandNum
(
len
(
elemArr
))
// should set random here too
}
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
v
al
)
val
:=
elemArr
[
idx
]
total
=
appendValues
(
&
items
,
val
,
repeat
,
tot
al
)
total
++
if
total
>
constant
.
MaxNumb
{
if
total
>=
constant
.
MaxNumb
{
break
}
i
+=
step
}
}
else
if
repeatTag
==
"!"
{
isRand
:=
field
.
Path
==
""
&&
stepStr
==
"r"
for
i
:=
0
;
i
<
repeat
;
{
total
=
appendArrItems
(
&
items
,
elemArr
,
total
,
isRand
)
if
total
>=
constant
.
MaxNumb
{
break
if
total
>=
constant
.
MaxNumb
{
break
}
i
+=
step
}
i
+=
step
}
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
// for ranges and instances, random
...
...
@@ -206,7 +210,7 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
return
}
func
CreateValuesFromInterval
(
field
*
model
.
DefField
,
desc
,
stepStr
string
,
repeat
int
)
(
items
[]
interface
{})
{
func
CreateValuesFromInterval
(
field
*
model
.
DefField
,
desc
,
stepStr
string
,
repeat
int
,
repeatTag
string
)
(
items
[]
interface
{})
{
elemArr
:=
strings
.
Split
(
desc
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
startStr
...
...
@@ -219,7 +223,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
if
field
.
Path
!=
""
&&
dataType
!=
"string"
&&
rand
{
// random. for res, field.Path == ""
items
=
append
(
items
,
Placeholder
(
field
.
Path
))
mp
:=
placeholderMapForRandValues
(
dataType
,
[]
string
{},
startStr
,
endStr
,
stepStr
,
strconv
.
Itoa
(
precision
),
field
.
Format
)
mp
:=
placeholderMapForRandValues
(
dataType
,
[]
string
{},
startStr
,
endStr
,
stepStr
,
strconv
.
Itoa
(
precision
),
field
.
Format
,
repeatTag
)
vari
.
RandFieldNameToValuesMap
[
field
.
Path
]
=
mp
return
...
...
@@ -229,17 +233,17 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
.
(
int
),
rand
,
repeat
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
.
(
int
),
rand
,
repeat
,
repeatTag
)
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
,
rand
,
repeat
)
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
,
rand
,
repeat
,
repeatTag
)
}
else
if
dataType
==
"char"
{
items
=
GenerateByteItems
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
),
rand
,
repeat
)
items
=
GenerateByteItems
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
),
rand
,
repeat
,
repeatTag
)
}
else
if
dataType
==
"string"
{
if
repeat
==
0
{
...
...
@@ -257,7 +261,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
return
}
func
CreateValuesFromYaml
(
field
*
model
.
DefField
,
yamlFile
,
stepStr
string
,
repeat
int
)
(
items
[]
interface
{})
{
func
CreateValuesFromYaml
(
field
*
model
.
DefField
,
yamlFile
,
stepStr
string
,
repeat
int
,
repeatTag
string
)
(
items
[]
interface
{})
{
// keep root def, since vari.ZdDef will be overwrite by refer yaml file
rootDef
:=
vari
.
Def
defaultDir
:=
vari
.
DefaultFileDir
...
...
@@ -293,18 +297,52 @@ func Placeholder(str string) string {
return
"${"
+
str
+
"}"
}
func
placeholderMapForRandValues
(
tp
string
,
list
[]
string
,
start
,
end
,
step
,
precision
,
format
string
)
map
[
string
]
interface
{}
{
func
placeholderMapForRandValues
(
tp
string
,
list
[]
string
,
start
,
end
,
step
,
precision
,
format
string
,
repeatTag
string
)
map
[
string
]
interface
{}
{
ret
:=
map
[
string
]
interface
{}{}
ret
[
"type"
]
=
tp
ret
[
"list"
]
=
list
// for literal values
// for literal values
ret
[
"list"
]
=
list
ret
[
"start"
]
=
start
// for interval values
// for interval values
ret
[
"start"
]
=
start
ret
[
"end"
]
=
end
ret
[
"step"
]
=
step
ret
[
"precision"
]
=
precision
ret
[
"format"
]
=
format
ret
[
"repeatTag"
]
=
repeatTag
return
ret
}
func
appendValues
(
items
*
[]
interface
{},
val
string
,
repeat
int
,
total
int
)
int
{
for
round
:=
0
;
round
<
repeat
;
round
++
{
*
items
=
append
(
*
items
,
val
)
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
return
total
}
func
appendArrItems
(
items
*
[]
interface
{},
arr
[]
string
,
total
int
,
isRand
bool
)
int
{
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
idx
:=
i
if
isRand
{
idx
=
commonUtils
.
RandNum
(
len
(
arr
))
// should set random here too
}
*
items
=
append
(
*
items
,
arr
[
idx
])
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
return
total
}
src/gen/parser.go
浏览文件 @
f063edb1
...
...
@@ -83,7 +83,7 @@ func ParseDesc(desc string) (items []string) {
step =>1
repeat =>2
*/
func
ParseRangeSection
(
item
string
)
(
entry
string
,
step
string
,
repeat
int
)
{
func
ParseRangeSection
(
item
string
)
(
entry
string
,
step
string
,
repeat
int
,
repeatTag
string
)
{
item
=
strings
.
TrimSpace
(
item
)
if
item
==
""
{
...
...
@@ -103,11 +103,18 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
return
}
regx
:=
regexp
.
MustCompile
(
`\{(.*)\}`
)
regx
:=
regexp
.
MustCompile
(
`\{(.*)
!?
\}`
)
arr
:=
regx
.
FindStringSubmatch
(
item
)
tag
:=
""
if
len
(
arr
)
==
2
{
repeat
,
_
=
strconv
.
Atoi
(
arr
[
1
])
str
:=
strings
.
TrimSpace
(
arr
[
1
])
if
str
[
len
(
str
)
-
1
:
]
==
"!"
{
tag
=
str
[
len
(
str
)
-
1
:
]
str
=
strings
.
TrimSpace
(
str
[
:
len
(
str
)
-
1
])
}
repeat
,
_
=
strconv
.
Atoi
(
str
)
}
repeatTag
=
tag
itemWithoutRepeat
:=
regx
.
ReplaceAllString
(
item
,
""
)
sectionArr
:=
strings
.
Split
(
itemWithoutRepeat
,
":"
)
...
...
@@ -128,7 +135,7 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
if
repeat
==
0
{
repeat
=
1
}
return
entry
,
step
,
repeat
return
entry
,
step
,
repeat
,
repeatTag
}
/**
...
...
@@ -162,7 +169,7 @@ func ParseRangeSectionDesc(str string) (typ string, desc string) {
for
_
,
item
:=
range
arr
{
if
isScopeStr
(
item
)
&&
isCharOrNumberScope
(
item
)
{
// only support a-z and 0-9 in []
tempField
:=
model
.
DefField
{}
values
:=
CreateValuesFromInterval
(
&
tempField
,
item
,
""
,
1
)
values
:=
CreateValuesFromInterval
(
&
tempField
,
item
,
""
,
1
,
""
)
for
_
,
val
:=
range
values
{
temp
+=
InterfaceToStr
(
val
)
+
","
...
...
src/gen/printer.go
浏览文件 @
f063edb1
...
...
@@ -196,27 +196,28 @@ func getValForPlaceholder(placeholderStr string, count int) []string {
}
strs
:=
make
([]
string
,
0
)
repeatTag
:=
mp
[
"repeatTag"
]
.
(
string
)
if
tp
==
"int"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
helper
.
GetRandFromRange
(
"int"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
strs
=
helper
.
GetRandFromRange
(
"int"
,
start
,
end
,
"1"
,
repeat
,
repeatTag
,
precision
,
count
,
format
)
}
else
if
tp
==
"float"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
helper
.
GetRandFromRange
(
"float"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
strs
=
helper
.
GetRandFromRange
(
"float"
,
start
,
end
,
"1"
,
repeat
,
repeatTag
,
precision
,
count
,
format
)
}
else
if
tp
==
"char"
{
start
:=
mp
[
"start"
]
.
(
string
)
end
:=
mp
[
"end"
]
.
(
string
)
precision
:=
mp
[
"precision"
]
.
(
string
)
format
:=
mp
[
"format"
]
.
(
string
)
strs
=
helper
.
GetRandFromRange
(
"char"
,
start
,
end
,
"1"
,
repeat
,
precision
,
count
,
format
)
strs
=
helper
.
GetRandFromRange
(
"char"
,
start
,
end
,
"1"
,
repeat
,
repeatTag
,
precision
,
count
,
format
)
}
else
if
tp
==
"list"
{
list
:=
mp
[
"list"
]
.
([]
string
)
strs
=
helper
.
GetRandFromList
(
list
,
repeat
,
count
)
...
...
src/gen/text.go
浏览文件 @
f063edb1
...
...
@@ -56,7 +56,7 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit
}
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
step
,
rand
,
1
)
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
step
,
rand
,
1
,
""
)
// get data by index
index
:=
0
for
_
,
numb
:=
range
numbs
{
...
...
src/gen/timestamp.go
浏览文件 @
f063edb1
...
...
@@ -58,7 +58,7 @@ func createTimestampSectionValue(section string, values *[]interface{}) {
}
// get index numbers for data retrieve
numbs
:=
GenerateIntItems
(
start
,
end
,
step
,
false
,
1
)
numbs
:=
GenerateIntItems
(
start
,
end
,
step
,
false
,
1
,
""
)
// generate data by index
index
:=
0
...
...
src/model/model.go
浏览文件 @
f063edb1
...
...
@@ -89,11 +89,12 @@ type ZdSection struct {
Ord
int
`gorm:"column:ord;default:1" json:"ord"`
// for range
Start
string
`gorm:"column:start" json:"start"`
End
string
`gorm:"column:end" json:"end"`
Step
int
`gorm:"column:step;default:1" json:"step"`
Repeat
string
`gorm:"column:repeat;default:1" json:"repeat"`
Rand
bool
`gorm:"column:rand;default:false" json:"rand"`
Start
string
`gorm:"column:start" json:"start"`
End
string
`gorm:"column:end" json:"end"`
Step
int
`gorm:"column:step;default:1" json:"step"`
Repeat
string
`gorm:"column:repeat;default:1" json:"repeat"`
RepeatTag
string
`gorm:"column:repeatTag" json:"repeatTag"`
Rand
bool
`gorm:"column:rand;default:false" json:"rand"`
// for arr and const
Text
string
`gorm:"-" json:"-"`
...
...
@@ -117,6 +118,7 @@ type ZdRefer struct {
ColIndex
int
`gorm:"column:colIndex" json:"colIndex"`
Condition
string
`gorm:"column:condition" json:"condition"`
Count
int
`gorm:"column:count" json:"count"`
CountTag
string
`gorm:"column:countTag" json:"countTag"`
Step
int
`gorm:"column:step" json:"step"`
Rand
bool
`gorm:"column:rand" json:"rand"`
HasTitle
bool
`gorm:"column:hasTitle" json:"hasTitle"`
...
...
src/server/repo/section.go
浏览文件 @
f063edb1
...
...
@@ -39,7 +39,7 @@ func (r *SectionRepo) Remove(id uint, ownerType string) (err error) {
}
func
(
r
*
SectionRepo
)
SaveFieldSectionToDB
(
rangeSection
string
,
ord
int
,
fieldID
uint
,
ownerType
string
)
{
descStr
,
stepStr
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
descStr
,
stepStr
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
typ
,
desc
:=
gen
.
ParseRangeSectionDesc
(
descStr
)
if
typ
==
"literal"
&&
desc
[
:
1
]
==
string
(
constant
.
LeftBrackets
)
&&
...
...
@@ -70,7 +70,7 @@ func (r *SectionRepo) SaveFieldSectionToDB(rangeSection string, ord int, fieldID
section
:=
model
.
ZdSection
{
OwnerType
:
ownerType
,
OwnerID
:
fieldID
,
Type
:
typ
,
Value
:
desc
,
Start
:
start
,
End
:
end
,
Ord
:
ord
,
Step
:
step
,
Repeat
:
countStr
,
Rand
:
rand
}
Step
:
step
,
Repeat
:
countStr
,
R
epeatTag
:
countTag
,
R
and
:
rand
}
r
.
Create
(
&
section
)
}
...
...
src/server/service/def.go
浏览文件 @
f063edb1
...
...
@@ -263,9 +263,10 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections
:=
gen
.
ParseRangeProperty
(
field
.
Use
)
if
len
(
rangeSections
)
>
0
{
// only get the first one
rangeSection
:=
rangeSections
[
0
]
desc
,
_
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
// medium{2
}
desc
,
_
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
// medium{2!
}
refer
.
ColName
=
desc
refer
.
Count
=
count
refer
.
CountTag
=
countTag
}
path
:=
fileUtils
.
ConvertReferRangeToPath
(
field
.
From
,
currPath
)
...
...
@@ -278,8 +279,9 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections
:=
gen
.
ParseRangeProperty
(
field
.
Config
)
// dir/config.yaml
if
len
(
rangeSections
)
>
0
{
// only get the first one
rangeSection
:=
rangeSections
[
0
]
desc
,
_
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
desc
,
_
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
refer
.
Count
=
count
refer
.
CountTag
=
countTag
path
:=
fileUtils
.
ConvertReferRangeToPath
(
desc
,
currPath
)
refer
.
File
=
GetRelatedPathWithResDir
(
path
)
...
...
@@ -289,8 +291,8 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections
:=
gen
.
ParseRangeProperty
(
field
.
Range
)
if
len
(
rangeSections
)
>
0
{
rangeSection
:=
rangeSections
[
0
]
// deal with yaml and text refer using range prop
desc
,
step
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
// dir/users.txt:R{3}
rangeSection
:=
rangeSections
[
0
]
// deal with yaml and text refer using range prop
desc
,
step
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
// dir/users.txt:R{3}
if
path
.
Ext
(
desc
)
==
".txt"
||
path
.
Ext
(
desc
)
==
".yaml"
{
if
path
.
Ext
(
desc
)
==
".txt"
{
// dir/users.txt:2
refer
.
Type
=
constant
.
ResTypeText
...
...
@@ -305,6 +307,7 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
refer
.
Type
=
constant
.
ResTypeYaml
refer
.
Count
=
count
refer
.
CountTag
=
countTag
}
path
:=
fileUtils
.
ConvertReferRangeToPath
(
desc
,
currPath
)
...
...
src/server/service/instances.go
浏览文件 @
f063edb1
...
...
@@ -230,9 +230,10 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
rangeSections
:=
gen
.
ParseRangeProperty
(
item
.
Use
)
if
len
(
rangeSections
)
>
0
{
// only get the first one
rangeSection
:=
rangeSections
[
0
]
desc
,
_
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
// medium{2}
desc
,
_
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
// medium{2}
refer
.
ColName
=
desc
refer
.
Count
=
count
refer
.
CountTag
=
countTag
}
path
:=
fileUtils
.
ConvertReferRangeToPath
(
item
.
From
,
currPath
)
...
...
@@ -245,8 +246,9 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
rangeSections
:=
gen
.
ParseRangeProperty
(
item
.
Config
)
// dir/config.yaml
if
len
(
rangeSections
)
>
0
{
// only get the first one
rangeSection
:=
rangeSections
[
0
]
desc
,
_
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
desc
,
_
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
refer
.
Count
=
count
refer
.
CountTag
=
countTag
path
:=
fileUtils
.
ConvertReferRangeToPath
(
desc
,
currPath
)
refer
.
File
=
GetRelatedPathWithResDir
(
path
)
...
...
@@ -257,7 +259,7 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
rangeSections
:=
gen
.
ParseRangeProperty
(
item
.
Range
)
if
len
(
rangeSections
)
>
0
{
// only get the first one
rangeSection
:=
rangeSections
[
0
]
desc
,
step
,
count
:=
gen
.
ParseRangeSection
(
rangeSection
)
// dir/users.txt:R{3}
desc
,
step
,
count
,
countTag
:=
gen
.
ParseRangeSection
(
rangeSection
)
// dir/users.txt:R{3}
if
path
.
Ext
(
desc
)
==
".txt"
||
path
.
Ext
(
desc
)
==
".yaml"
{
if
path
.
Ext
(
desc
)
==
".txt"
{
// dir/users.txt:2
refer
.
Type
=
constant
.
ResTypeText
...
...
@@ -272,6 +274,7 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
refer
.
Type
=
constant
.
ResTypeYaml
refer
.
Count
=
count
refer
.
CountTag
=
countTag
}
path
:=
fileUtils
.
ConvertReferRangeToPath
(
desc
,
currPath
)
...
...
test/test.yaml
0 → 100755
浏览文件 @
f063edb1
title
:
range
desc
:
描述
version
:
1.0
fields
:
-
field
:
field_length
range
:
1-3{2!}
length
:
3
leftpad
:
0
prefix
:
"
+"
postfix
:
"
-"
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录