Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
10bf813c
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 搜索 >>
提交
10bf813c
编写于
7月 29, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gen random value for ${fieldPath}
上级
67661635
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
187 addition
and
187 deletion
+187
-187
demo/smoke.yaml
demo/smoke.yaml
+4
-4
src/gen/generator.go
src/gen/generator.go
+29
-34
src/gen/intVal.go
src/gen/intVal.go
+37
-38
src/gen/list.go
src/gen/list.go
+30
-16
src/gen/rand.go
src/gen/rand.go
+83
-0
src/gen/session.go
src/gen/session.go
+0
-46
src/gen/text.go
src/gen/text.go
+1
-1
src/gen/timestamp.go
src/gen/timestamp.go
+0
-47
src/model/definition.go
src/model/definition.go
+2
-1
src/utils/vari/var.go
src/utils/vari/var.go
+1
-0
未找到文件。
demo/smoke.yaml
浏览文件 @
10bf813c
...
...
@@ -30,20 +30,20 @@ fields:
fields
:
-
field
:
child1
range
:
X-Z
prefix
:
"
a'b
"
postfix
:
"
\t
<:
\"
(`[]{}
"
prefix
:
"
"
postfix
:
"
\t
"
-
field
:
child2
prefix
:
"
["
postfix
:
"
]"
fields
:
-
field
:
child2.1
range
:
a-
c
range
:
a-
b
prefix
:
postfix
:
"
\t
"
-
field
:
child2.2
range
:
1-9
range
:
1-9
:R
prefix
:
loop
:
3
loopfix
:
"
,"
src/gen/generator.go
浏览文件 @
10bf813c
...
...
@@ -18,8 +18,7 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
vari
.
Def
=
LoadConfigDef
(
defaultFile
,
configFile
,
fieldsToExport
)
vari
.
Res
=
LoadResDef
(
*
fieldsToExport
)
fieldNameToValues
:=
map
[
string
][]
string
{}
topFieldNameToValuesMap
:=
map
[
string
][]
string
{}
colIsNumArr
:=
make
([]
bool
,
0
)
// 为每个field生成值列表
...
...
@@ -31,7 +30,7 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
values
:=
GenerateForField
(
&
field
,
total
,
true
)
vari
.
Def
.
Fields
[
index
]
.
Precision
=
field
.
Precision
fieldNameToValues
[
field
.
Field
]
=
values
topFieldNameToValuesMap
[
field
.
Field
]
=
values
colIsNumArr
=
append
(
colIsNumArr
,
field
.
IsNumb
)
}
...
...
@@ -43,7 +42,7 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
continue
}
values
:=
fieldNameToValues
[
field
.
Field
]
values
:=
topFieldNameToValuesMap
[
field
.
Field
]
fieldVal
:=
values
[
i
%
len
(
values
)]
if
len
(
rows
)
==
i
{
rows
=
append
(
rows
,
make
([]
string
,
0
))
}
rows
[
i
]
=
append
(
rows
[
i
],
fieldVal
)
...
...
@@ -53,9 +52,7 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
return
rows
,
colIsNumArr
}
func
GenerateForField
(
field
*
model
.
DefField
,
total
int
,
withFix
bool
)
[]
string
{
values
:=
make
([]
string
,
0
)
func
GenerateForField
(
field
*
model
.
DefField
,
total
int
,
withFix
bool
)
(
values
[]
string
)
{
if
len
(
field
.
Fields
)
>
0
{
// sub fields
arrOfArr
:=
make
([][]
string
,
0
)
// 2 dimension arr for child, [ [a,b,c], [1,2,3] ]
for
_
,
child
:=
range
field
.
Fields
{
...
...
@@ -64,7 +61,7 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
}
count
:=
total
if
strings
.
Index
(
field
.
Path
,
""
)
>
-
1
{
// is child, gen
x*
y records
if
strings
.
Index
(
field
.
Path
,
""
)
>
-
1
{
// is child, gen
num = x *
y records
count
=
getRecordCount
(
arrOfArr
)
if
count
>
total
{
count
=
total
...
...
@@ -102,7 +99,8 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
}
else
if
field
.
Config
!=
""
{
// refer to another define
groupValues
:=
vari
.
Res
[
field
.
Config
]
values
=
append
(
values
,
groupValues
[
"all"
]
...
)
}
else
{
// basic field
}
else
{
// leaf field
values
=
GenerateFieldItemsFromDefinition
(
field
)
}
...
...
@@ -110,21 +108,21 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
}
func
GenerateFieldItemsFromDefinition
(
field
*
model
.
DefField
)
[]
string
{
//if field.Loop == "" {field.Loop = "1"}
values
:=
make
([]
string
,
0
)
//valuesWithPlaceholder := make([]string, 0)
//vari.RandFieldNameToValuesMap[field.Path] = valuesWithPlaceholder
field
Value
:=
GenerateList
(
field
)
field
WithValues
:=
GenerateList
(
field
)
index
:=
0
count
:=
0
for
{
// 处理格式、前后缀、loop等
str
:=
GenerateFieldValWithFix
(
field
,
fieldValue
,
&
index
,
true
)
values
=
append
(
values
,
str
)
val
:=
GenerateFieldValWithFix
(
field
,
fieldWithValues
,
&
index
,
true
)
values
=
append
(
values
,
val
)
count
++
if
index
>=
len
(
field
Value
.
Values
)
||
count
>=
vari
.
Total
{
if
index
>=
len
(
field
WithValues
.
Values
)
||
count
>=
vari
.
Total
{
break
}
}
...
...
@@ -132,17 +130,6 @@ func GenerateFieldItemsFromDefinition(field *model.DefField) []string {
return
values
}
func
GenerateFieldVal
(
field
model
.
DefField
,
fieldValue
model
.
FieldValue
,
index
*
int
)
string
{
str
:=
""
// 叶节点
idx
:=
*
index
%
len
(
fieldValue
.
Values
)
val
:=
fieldValue
.
Values
[
idx
]
str
=
GetFieldValStr
(
field
,
val
)
return
str
}
func
GetFieldValStr
(
field
model
.
DefField
,
val
interface
{})
string
{
str
:=
"n/a"
success
:=
false
...
...
@@ -183,11 +170,9 @@ func GetFieldValStr(field model.DefField, val interface{}) string {
return
str
}
func
LoopSubFields
(
field
*
model
.
DefField
,
oldValues
[]
string
,
total
int
,
withFix
bool
)
[]
string
{
//if field.Loop == "" {field.Loop = "1"}
func
LoopSubFields
(
field
*
model
.
DefField
,
oldValues
[]
string
,
total
int
,
withFix
bool
)
(
values
[]
string
)
{
values
:=
make
([]
string
,
0
)
fieldValue
:=
model
.
FieldValue
{}
fieldValue
:=
model
.
FieldWithValues
{}
for
_
,
val
:=
range
oldValues
{
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
val
)
...
...
@@ -206,15 +191,16 @@ func LoopSubFields(field *model.DefField, oldValues []string, total int, withFix
}
}
return
values
return
}
func
GenerateFieldValWithFix
(
field
*
model
.
DefField
,
fieldValue
model
.
FieldValue
,
indexOfRow
*
int
,
withFix
bool
)
string
{
func
GenerateFieldValWithFix
(
field
*
model
.
DefField
,
fieldValue
model
.
FieldWithValues
,
indexOfRow
*
int
,
withFix
bool
)
(
loopStr
string
)
{
prefix
:=
field
.
Prefix
postfix
:=
field
.
Postfix
computerLoop
(
field
)
loopStr
:=
""
for
j
:=
0
;
j
<
(
*
field
)
.
LoopIndex
;
j
++
{
if
loopStr
!=
""
{
loopStr
=
loopStr
+
field
.
Loopfix
...
...
@@ -239,7 +225,16 @@ func GenerateFieldValWithFix(field *model.DefField, fieldValue model.FieldValue,
(
*
field
)
.
LoopIndex
=
(
*
field
)
.
LoopStart
}
return
loopStr
return
}
func
GenerateFieldVal
(
field
model
.
DefField
,
fieldValue
model
.
FieldWithValues
,
index
*
int
)
(
val
string
)
{
// 叶节点
idx
:=
*
index
%
len
(
fieldValue
.
Values
)
str
:=
fieldValue
.
Values
[
idx
]
val
=
GetFieldValStr
(
field
,
str
)
return
}
func
computerLoop
(
field
*
model
.
DefField
)
{
...
...
src/gen/intVal.go
浏览文件 @
10bf813c
package
gen
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
)
func
GenerateIntItems
(
start
int64
,
end
int64
,
step
interface
{},
rand
bool
,
limit
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateIntItemsByStep
(
start
,
end
,
step
.
(
int
),
limit
)
}
else
{
return
GenerateIntItemsRand
(
start
,
end
,
step
.
(
int
),
limit
)
}
}
//
func GenerateIntItems(start int64, end int64, step interface{}, rand bool, limit int) []interface{} {
//
if !rand {
//
return GenerateIntItemsByStep(start, end, step.(int), limit)
//
} else{
//
return GenerateIntItemsRand(start, end, step.(int), limit)
//
}
//
}
func
GenerateIntItemsByStep
(
start
int64
,
end
int64
,
step
int
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
...
...
@@ -41,33 +40,33 @@ func GenerateIntItemsByStep(start int64, end int64, step int, repeat int) []inte
return
arr
}
func
GenerateIntItemsRand
(
start
int64
,
end
int64
,
step
int
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
countInRound
:=
(
end
-
start
)
/
int64
(
step
)
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
)
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
if
total
>
constant
.
MaxNumb
{
break
}
i
++
}
return
arr
}
\ No newline at end of file
//func GenerateIntItemsRand(start int64, end int64, step int, repeat int) []interface{} {
// arr := make([]interface{}, 0)
//
// countInRound := (end - start) / int64(step)
// 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)
//
// total++
//
// if total > constant.MaxNumb {
// break
// }
// }
//
// if total > constant.MaxNumb {
// break
// }
// i++
// }
//
// return arr
//}
\ No newline at end of file
src/gen/list.go
浏览文件 @
10bf813c
...
...
@@ -8,20 +8,20 @@ import (
"strings"
)
func
GenerateList
(
field
*
model
.
DefField
)
model
.
Field
Value
{
fieldValue
:=
model
.
Field
Value
{}
func
GenerateList
(
field
*
model
.
DefField
)
model
.
Field
WithValues
{
fieldValue
:=
model
.
Field
WithValues
{}
GenerateListField
(
field
,
&
fieldValue
)
return
fieldValue
}
func
GenerateListField
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
Value
)
{
func
GenerateListField
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
WithValues
)
{
fieldValue
.
Field
=
field
.
Field
fieldValue
.
Precision
=
field
.
Precision
if
len
(
field
.
Fields
)
>
0
{
for
_
,
child
:=
range
field
.
Fields
{
childValue
:=
model
.
Field
Value
{}
childValue
:=
model
.
Field
WithValues
{}
GenerateListField
(
&
child
,
&
childValue
)
}
}
else
{
...
...
@@ -29,7 +29,7 @@ func GenerateListField(field *model.DefField, fieldValue *model.FieldValue) {
}
}
func
GenerateFieldValues
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
Value
)
{
func
GenerateFieldValues
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
WithValues
)
{
if
strings
.
Index
(
field
.
Range
,
".txt"
)
>
-
1
{
GenerateFieldValuesFromText
(
field
,
fieldValue
)
}
else
{
...
...
@@ -37,7 +37,7 @@ func GenerateFieldValues(field *model.DefField, fieldValue *model.FieldValue) {
}
}
func
GenerateFieldValuesFromList
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
Value
)
{
func
GenerateFieldValuesFromList
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
WithValues
)
{
rang
:=
field
.
Range
rangeItems
:=
ParseRange
(
rang
)
// 1
...
...
@@ -50,13 +50,15 @@ func GenerateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldV
typ
,
desc
:=
ParseEntry
(
entry
)
// 2
items
:=
make
([]
interface
{},
0
)
itemsWithPlaceholder
:=
make
([]
string
,
0
)
if
typ
==
"literal"
{
items
=
GenerateValuesFromLiteral
(
desc
,
stepStr
,
repeat
)
items
=
GenerateValuesFromLiteral
(
field
,
desc
,
stepStr
,
repeat
)
}
else
if
typ
==
"interval"
{
items
=
GenerateValuesFromInterval
(
field
,
desc
,
stepStr
,
repeat
)
}
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
items
...
)
fieldValue
.
ValuesWithPlaceholder
=
append
(
fieldValue
.
ValuesWithPlaceholder
,
itemsWithPlaceholder
...
)
index
=
index
+
len
(
items
)
}
...
...
@@ -137,8 +139,7 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
return
"string"
,
1
,
0
,
false
// is string
}
func
GenerateValuesFromLiteral
(
desc
string
,
stepStr
string
,
repeat
int
)
[]
interface
{}
{
items
:=
make
([]
interface
{},
0
)
func
GenerateValuesFromLiteral
(
field
*
model
.
DefField
,
desc
string
,
stepStr
string
,
repeat
int
)
(
items
[]
interface
{})
{
elemArr
:=
strings
.
Split
(
desc
,
","
)
step
,
_
:=
strconv
.
Atoi
(
stepStr
)
...
...
@@ -146,6 +147,7 @@ func GenerateValuesFromLiteral(desc string, stepStr string, repeat int) []interf
for
i
:=
0
;
i
<
len
(
elemArr
);
{
val
:=
""
if
stepStr
==
"r"
{
val
=
elemArr
[
commonUtils
.
RandNum
(
len
(
elemArr
))]
}
else
{
...
...
@@ -167,31 +169,43 @@ func GenerateValuesFromLiteral(desc string, stepStr string, repeat int) []interf
i
+=
step
}
return
items
return
}
func
GenerateValuesFromInterval
(
field
*
model
.
DefField
,
desc
string
,
stepStr
string
,
repeat
int
)
[]
interface
{}
{
func
GenerateValuesFromInterval
(
field
*
model
.
DefField
,
desc
string
,
stepStr
string
,
repeat
int
)
(
items
[]
interface
{})
{
elemArr
:=
strings
.
Split
(
desc
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
startStr
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
items
:=
make
([]
interface
{},
0
)
dataType
,
step
,
precision
,
rand
:=
CheckRangeType
(
startStr
,
endStr
,
stepStr
)
if
dataType
==
"int"
{
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
,
rand
,
repeat
)
if
!
rand
{
items
=
GenerateIntItemsByStep
(
startInt
,
endInt
,
step
.
(
int
),
repeat
)
}
else
{
items
=
append
(
items
,
field
.
Path
)
}
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
.
(
float64
),
rand
,
repeat
)
if
!
rand
{
items
=
GenerateFloatItemsByStep
(
startFloat
,
endFloat
,
step
.
(
int
),
repeat
)
}
else
{
items
=
append
(
items
,
field
.
Path
)
}
}
else
if
dataType
==
"char"
{
items
=
GenerateByteItems
(
byte
(
startStr
[
0
]),
byte
(
endStr
[
0
]),
step
,
rand
,
repeat
)
if
!
rand
{
items
=
GenerateByteItemsByStep
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
),
repeat
)
}
else
{
items
=
append
(
items
,
field
.
Path
)
}
}
else
if
dataType
==
"string"
{
if
repeat
==
0
{
repeat
=
1
}
for
i
:=
0
;
i
<
repeat
;
i
++
{
...
...
@@ -199,5 +213,5 @@ func GenerateValuesFromInterval(field *model.DefField, desc string, stepStr stri
}
}
return
items
return
}
src/gen/rand.go
0 → 100644
浏览文件 @
10bf813c
package
gen
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
"strconv"
"strings"
)
func
GetRandFromList
(
list
[]
string
,
repeat
int
)
string
{
rand
:=
commonUtils
.
RandNum
(
len
(
list
))
val
:=
list
[
rand
]
items
:=
make
([]
string
,
0
)
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
val
)
}
return
strings
.
Join
(
items
,
""
)
}
func
GetRandFromRange
(
dataType
,
start
,
end
,
step
string
,
repeat
,
precision
int
)
string
{
if
dataType
==
"int"
{
startInt
,
_
:=
strconv
.
ParseInt
(
start
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
end
,
0
,
64
)
stepInt
,
_
:=
strconv
.
ParseInt
(
step
,
0
,
64
)
countInRound
:=
(
startInt
-
endInt
)
/
stepInt
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
if
stepInt
<
0
{
rand
=
rand
*
-
1
}
val
:=
startInt
+
rand
items
:=
make
([]
string
,
0
)
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
string
(
val
))
}
return
strings
.
Join
(
items
,
""
)
}
else
if
dataType
==
"char"
{
startChar
:=
start
[
0
]
endChar
:=
end
[
0
]
stepInt
,
_
:=
strconv
.
ParseInt
(
step
,
0
,
64
)
countInRound
:=
int64
(
int64
(
endChar
)
-
int64
(
startChar
))
/
stepInt
rand
:=
commonUtils
.
RandNum64
(
countInRound
)
if
stepInt
<
0
{
rand
=
rand
*
-
1
}
val
:=
startChar
+
byte
(
rand
)
items
:=
make
([]
string
,
0
)
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
string
(
val
))
}
return
strings
.
Join
(
items
,
""
)
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
start
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
end
,
64
)
stepFloat
,
_
:=
strconv
.
ParseFloat
(
step
,
64
)
countInRound
:=
(
startFloat
-
endFloat
)
/
stepFloat
rand
:=
commonUtils
.
RandNum64
(
int64
(
countInRound
))
if
stepFloat
<
0
{
rand
=
rand
*
-
1
}
val
:=
startFloat
+
float64
(
rand
)
*
stepFloat
items
:=
make
([]
string
,
0
)
for
round
:=
0
;
round
<
repeat
;
round
++
{
str
:=
strconv
.
FormatFloat
(
val
,
'f'
,
precision
,
64
)
items
=
append
(
items
,
str
)
return
strings
.
Join
(
items
,
""
)
}
}
return
"N/A"
}
\ No newline at end of file
src/gen/session.go
已删除
100644 → 0
浏览文件 @
67661635
package
gen
import
(
"github.com/easysoft/zendata/src/model"
"strconv"
"strings"
)
func
GenerateSessionId
(
field
*
model
.
DefField
,
total
int
,
fieldMap
map
[
string
][]
interface
{})
{
name
:=
strings
.
TrimSpace
(
field
.
Note
)
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
stepStr
:=
strings
.
TrimSpace
(
"field.Step"
)
rangeItems
:=
strings
.
Split
(
rang
,
","
)
index
:=
0
for
_
,
item
:=
range
rangeItems
{
if
index
>=
total
{
break
}
if
strings
.
TrimSpace
(
item
)
==
""
{
continue
}
elemArr
:=
strings
.
Split
(
item
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
""
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
items
:=
make
([]
interface
{},
0
)
startInt
,
errInt1
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
errInt2
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
if
errInt1
==
nil
&&
errInt2
==
nil
{
// int
step
,
errInt3
:=
strconv
.
Atoi
(
stepStr
)
if
errInt3
!=
nil
{
step
=
1
}
items
=
GenerateIntItems
(
startInt
,
endInt
,
int64
(
step
),
true
,
1
)
}
fieldMap
[
name
]
=
append
(
fieldMap
[
name
],
items
...
)
index
=
index
+
len
(
items
)
}
}
\ No newline at end of file
src/gen/text.go
浏览文件 @
10bf813c
...
...
@@ -15,7 +15,7 @@ import (
"strings"
)
func
GenerateFieldValuesFromText
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
Value
)
{
func
GenerateFieldValuesFromText
(
field
*
model
.
DefField
,
fieldValue
*
model
.
Field
WithValues
)
{
// get file and step string
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
sectionArr
:=
strings
.
Split
(
rang
,
":"
)
...
...
src/gen/timestamp.go
已删除
100644 → 0
浏览文件 @
67661635
package
gen
import
(
"github.com/easysoft/zendata/src/model"
dateUtils
"github.com/easysoft/zendata/src/utils/date"
"strconv"
"strings"
)
func
GenerateTimestamp
(
field
*
model
.
DefField
,
total
int
,
fieldMap
map
[
string
][]
interface
{})
{
name
:=
strings
.
TrimSpace
(
field
.
Note
)
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
stepStr
:=
strings
.
TrimSpace
(
"field.Step"
)
rangeItems
:=
strings
.
Split
(
rang
,
","
)
index
:=
0
for
_
,
item
:=
range
rangeItems
{
if
index
>=
total
{
break
}
if
strings
.
TrimSpace
(
item
)
==
""
{
continue
}
elemArr
:=
strings
.
Split
(
item
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
""
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
items
:=
make
([]
interface
{},
0
)
start
,
err1
:=
dateUtils
.
DateStrToTimestamp
(
startStr
)
end
,
err2
:=
dateUtils
.
DateStrToTimestamp
(
endStr
)
if
err1
==
nil
&&
err2
==
nil
{
step
,
err3
:=
strconv
.
Atoi
(
stepStr
)
if
err3
!=
nil
{
step
=
1000
// default 1 sec
}
items
=
GenerateIntItems
(
start
,
end
,
int64
(
step
),
true
,
1
)
}
fieldMap
[
name
]
=
append
(
fieldMap
[
name
],
items
...
)
index
=
index
+
len
(
items
)
}
}
\ No newline at end of file
src/model/definition.go
浏览文件 @
10bf813c
...
...
@@ -74,10 +74,11 @@ type FieldSimple struct {
LoopIndex
int
}
type
Field
Value
struct
{
type
Field
WithValues
struct
{
FieldBase
`yaml:",inline"`
Field
string
`yaml:"field"`
Values
[]
interface
{}
ValuesWithPlaceholder
[]
string
}
func
(
def
*
DefSimple
)
Init
(
tableName
,
author
,
desc
,
version
string
)
{
...
...
src/utils/vari/var.go
浏览文件 @
10bf813c
...
...
@@ -32,6 +32,7 @@ var (
Def
=
model
.
DefData
{}
Res
=
map
[
string
]
map
[
string
][]
string
{}
RandFieldNameToValuesMap
=
map
[
string
][]
string
{}
DefaultDir
string
ConfigDir
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录