Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
24722e8c
Z
zendata
项目概览
易企天创
/
zendata
8 个月 前同步成功
通知
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 搜索 >>
提交
24722e8c
编写于
4月 03, 2023
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issues
上级
6c79edf9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
99 addition
and
96 deletion
+99
-96
internal/pkg/helper/column-generate.go
internal/pkg/helper/column-generate.go
+9
-9
internal/pkg/helper/column.go
internal/pkg/helper/column.go
+70
-74
internal/pkg/helper/format.go
internal/pkg/helper/format.go
+13
-7
internal/pkg/service/from-sql.go
internal/pkg/service/from-sql.go
+2
-1
test/t.yaml
test/t.yaml
+1
-1
test/test-format.yaml
test/test-format.yaml
+4
-4
未找到文件。
internal/pkg/helper/column-generate.go
浏览文件 @
24722e8c
...
...
@@ -2,6 +2,7 @@ package helper
import
(
"fmt"
"math"
"strconv"
)
...
...
@@ -50,9 +51,9 @@ func GenInt(hasSign bool) (ret, note string) {
}
func
GenBigint
(
hasSign
bool
)
(
ret
,
note
string
)
{
if
hasSign
{
ret
=
"-9223372036854775808-9223372036854775807:R"
ret
=
fmt
.
Sprintf
(
"%d-%d:R"
,
math
.
MinInt64
,
math
.
MaxInt64
)
}
else
{
ret
=
"0-18446744073709551615:R"
ret
=
fmt
.
Sprintf
(
"0-%d:R"
,
math
.
MaxInt64
)
}
note
=
"bigint 2^64"
...
...
@@ -90,20 +91,19 @@ func GenDecimal(hasSign bool) (ret, note string) {
return
}
func
GenChar
(
param
string
)
(
ret
string
)
{
r
ang
:
=
`a-z`
func
GenChar
(
param
string
)
(
ret
string
,
loop
string
)
{
r
et
=
`a-z`
paramInt
,
_
:=
strconv
.
Atoi
(
param
)
if
paramInt
>
0
{
rang
+=
fmt
.
Sprintf
(
"{%d!}"
,
paramInt
)
loopInt
,
_
:=
strconv
.
Atoi
(
param
)
if
loopInt
>
0
{
loop
=
fmt
.
Sprintf
(
"%d"
,
loopInt
)
}
return
}
func
GenBin
()
(
from
,
format
string
)
{
format
=
"binary"
format
=
"binary
()
"
return
}
...
...
internal/pkg/helper/column.go
浏览文件 @
24722e8c
...
...
@@ -85,7 +85,7 @@ func generateDefByVarcharType(param string, info *FieldTypeInfo) {
info
.
Use
=
"length32_random"
}
else
if
info
.
VarcharType
==
consts
.
JsonStr
{
info
.
Format
=
"
id_card
()"
info
.
Format
=
"
json
()"
}
else
if
info
.
VarcharType
==
consts
.
Md5
{
info
.
Rang
=
"1-100"
...
...
@@ -213,28 +213,33 @@ func GetVarcharTypeByRecords(records []interface{}) (ret consts.VarcharType) {
if
govalidator
.
IsEmail
(
val
)
{
ret
=
consts
.
Email
}
else
if
govalidator
.
IsCreditCard
(
val
)
{
ret
=
consts
.
CreditCard
}
else
if
govalidator
.
IsMAC
(
val
)
{
ret
=
consts
.
Mac
}
else
if
govalidator
.
IsUUID
(
val
)
{
ret
=
consts
.
Uuid
}
else
if
govalidator
.
IsJSON
(
val
)
{
ret
=
consts
.
JsonStr
//} else if govalidator.IsUnixTime(val) {
// ret = consts.UnixTime
}
else
if
govalidator
.
IsMD5
(
val
)
{
ret
=
consts
.
Md5
}
else
if
IsMobilePhone
(
val
)
{
ret
=
consts
.
MobileNumber
}
else
if
IsTelPhone
(
val
)
{
ret
=
consts
.
TelNumber
}
else
if
IsIDCard
(
val
)
{
ret
=
consts
.
IdCard
}
else
if
govalidator
.
IsURL
(
val
)
{
ret
=
consts
.
Url
}
else
if
govalidator
.
IsJSON
(
val
)
{
ret
=
consts
.
JsonStr
}
return
...
...
@@ -248,141 +253,132 @@ type FieldTypeInfo struct {
Precision
int
HasSign
bool
Note
string
Rang
string
Type
string
Format
string
From
string
Use
string
Select
string
Prefix
string
Note
string
Rang
string
Loop
string
Loopfix
string
Type
string
Format
string
From
string
Use
string
Select
string
Prefix
string
}
func
GenDefByColumnType
(
param
string
,
ret
*
FieldTypeInfo
)
{
rang
:=
""
typ
:=
""
format
:=
""
from
:=
""
selectStr
:=
""
note
:=
""
switch
ret
.
ColumnType
{
// int
case
"bit"
:
r
ang
,
n
ote
=
GenBit
()
r
et
.
Rang
,
ret
.
N
ote
=
GenBit
()
case
"tinyint"
:
r
ang
,
n
ote
=
GenTinyint
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenTinyint
(
ret
.
HasSign
)
case
"smallint"
:
r
ang
,
n
ote
=
GenSmallint
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenSmallint
(
ret
.
HasSign
)
case
"mediumint"
:
r
ang
,
n
ote
=
GenMediumint
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenMediumint
(
ret
.
HasSign
)
case
"int"
:
r
ang
,
n
ote
=
GenInt
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenInt
(
ret
.
HasSign
)
case
"bigint"
:
r
ang
,
n
ote
=
GenBigint
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenBigint
(
ret
.
HasSign
)
// float
case
"float"
:
r
ang
,
n
ote
=
GenFloat
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenFloat
(
ret
.
HasSign
)
case
"double"
:
r
ang
,
n
ote
=
GenDouble
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenDouble
(
ret
.
HasSign
)
// fixed-point
case
"decimal"
:
r
ang
,
n
ote
=
GenDecimal
(
ret
.
HasSign
)
r
et
.
Rang
,
ret
.
N
ote
=
GenDecimal
(
ret
.
HasSign
)
// string
case
"char"
:
rang
=
GenChar
(
param
)
ret
.
Rang
,
ret
.
Loop
=
GenChar
(
param
)
case
"tinytext"
:
f
rom
=
"idiom.v1.idiom"
selectStr
=
"word"
ret
.
F
rom
=
"idiom.v1.idiom"
ret
.
Select
=
"word"
case
"text"
:
f
rom
=
"xiehouyu.v1.xiehouyu"
selectStr
=
"riddle"
ret
.
F
rom
=
"xiehouyu.v1.xiehouyu"
ret
.
Select
=
"riddle"
case
"mediumtext"
:
f
rom
=
"joke.v1.joke"
selectStr
=
"content"
ret
.
F
rom
=
"joke.v1.joke"
ret
.
Select
=
"content"
case
"longtext"
:
f
rom
=
"song.v1.song"
selectStr
=
"lyric"
ret
.
F
rom
=
"song.v1.song"
ret
.
Select
=
"lyric"
// binary data
case
"tinyblob"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
case
"blob"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
case
"mediumblob"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
case
"longblob"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
case
"binary"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
case
"varbinary"
:
from
,
f
ormat
=
GenBin
()
ret
.
From
,
ret
.
F
ormat
=
GenBin
()
// date and time type
case
"date"
:
r
ang
,
typ
,
f
ormat
=
GenDate
()
r
et
.
Rang
,
ret
.
Type
,
ret
.
F
ormat
=
GenDate
()
case
"time"
:
r
ang
,
typ
,
f
ormat
=
GenTime
()
r
et
.
Rang
,
ret
.
Type
,
ret
.
F
ormat
=
GenTime
()
case
"year"
:
r
ang
,
typ
,
f
ormat
=
GenYear
()
r
et
.
Rang
,
ret
.
Type
,
ret
.
F
ormat
=
GenYear
()
case
"datetime"
:
r
ang
,
typ
,
f
ormat
=
GenDatetime
()
r
et
.
Rang
,
ret
.
Type
,
ret
.
F
ormat
=
GenDatetime
()
case
"timestamp"
:
r
ang
,
typ
,
f
ormat
=
GenTimestamp
()
r
et
.
Rang
,
ret
.
Type
,
ret
.
F
ormat
=
GenTimestamp
()
// other type
case
"enum"
:
rang
=
getEnumValue
(
param
)
r
et
.
R
ang
=
getEnumValue
(
param
)
case
"set"
:
r
ang
=
getSetValue
(
param
)
r
et
.
Rang
,
ret
.
Loop
,
ret
.
Loopfix
=
getSetValue
(
param
)
//case "geometry":
// rang = `"geometry"`
// r
et.R
ang = `"geometry"`
//case "point":
// rang = `"point"`
// r
et.R
ang = `"point"`
//case "linestring":
// rang = `"linestring"`
// r
et.R
ang = `"linestring"`
//case "polygon":
// rang = `"polygon"`
// r
et.R
ang = `"polygon"`
//case "multipoint":
// rang = `"multipoint"`
// r
et.R
ang = `"multipoint"`
//case "multilinestring":
// rang = `"multilinestring"`
// r
et.R
ang = `"multilinestring"`
//case "multipolygon":
// rang = `"multipolygon"`
// r
et.R
ang = `"multipolygon"`
//case "geometrycollection":
// rang = `"geometrycollection"`
// r
et.R
ang = `"geometrycollection"`
default
:
}
ret
.
Rang
=
rang
ret
.
Format
=
format
ret
.
Type
=
typ
ret
.
From
=
from
ret
.
Select
=
selectStr
ret
.
Note
=
note
return
}
func
getEnumValue
(
param
string
)
(
ret
string
)
{
arr
:=
strings
.
Split
(
param
,
","
)
num
:=
getRandNum
(
len
(
arr
))
ret
=
strings
.
Trim
(
arr
[
num
],
"'"
)
ret
=
strings
.
ReplaceAll
(
param
,
"'"
,
""
)
return
}
func
getSetValue
(
param
string
)
(
ret
string
)
{
//arr := strings.Split(param, ",")
//ret = strings.Join(arr, ",")
func
getSetValue
(
param
string
)
(
ret
,
loop
,
loopfix
string
)
{
ret
=
strings
.
ReplaceAll
(
param
,
"'"
,
""
)
arr
:=
strings
.
Split
(
param
,
","
)
start
:=
1
if
len
(
arr
)
>
2
{
start
=
2
}
loop
=
fmt
.
Sprintf
(
"%d-%d"
,
start
,
len
(
arr
))
return
}
...
...
internal/pkg/helper/format.go
浏览文件 @
24722e8c
...
...
@@ -19,6 +19,7 @@ import (
)
func
FormatStr
(
format
string
,
val
interface
{},
precision
int
)
(
ret
string
,
pass
bool
)
{
format
=
strings
.
TrimSpace
(
format
)
if
format
==
""
{
return
val
.
(
string
),
true
}
...
...
@@ -47,12 +48,12 @@ func FormatStr(format string, val interface{}, precision int) (ret string, pass
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"uuid"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"uuid"
)
==
0
{
ret
=
GenerateUuid
(
format
)
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"password"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"password"
)
==
0
{
length
:=
8
regx
:=
regexp
.
MustCompile
(
`password\(\s*(\d+)\s*\)`
)
arr
:=
regx
.
FindStringSubmatch
(
format
)
...
...
@@ -67,12 +68,12 @@ func FormatStr(format string, val interface{}, precision int) (ret string, pass
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"binary"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"binary"
)
==
0
{
ret
=
ImgBindata
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"credit_card"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"credit_card"
)
==
0
{
cardType
:=
""
regx
:=
regexp
.
MustCompile
(
`credit_card\(\s*(\S+)\s*\)`
)
...
...
@@ -85,19 +86,24 @@ func FormatStr(format string, val interface{}, precision int) (ret string, pass
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"id_card"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"id_card"
)
==
0
{
ret
=
GenerateIdCard
()
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"mac"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"mac"
)
==
0
{
ret
=
GenerateMac
()
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"token"
)
>
-
1
{
}
else
if
strings
.
Index
(
format
,
"token"
)
==
0
{
ret
=
GenerateToken
(
format
)
pass
=
true
return
}
else
if
strings
.
Index
(
format
,
"json"
)
==
0
{
ret
=
Json
pass
=
true
return
}
...
...
internal/pkg/service/from-sql.go
浏览文件 @
24722e8c
...
...
@@ -243,11 +243,12 @@ func (s *SqlParseService) genTablesYaml(statementMap map[string]string,
field
.
Range
=
types
[
col
]
.
Rang
field
.
Type
=
types
[
col
]
.
Type
field
.
Loop
=
types
[
col
]
.
Loop
field
.
Format
=
types
[
col
]
.
Format
field
.
From
=
types
[
col
]
.
From
field
.
Use
=
types
[
col
]
.
Use
field
.
From
=
types
[
col
]
.
From
field
.
Select
=
types
[
col
]
.
From
field
.
Select
=
types
[
col
]
.
Select
field
.
Prefix
=
types
[
col
]
.
Prefix
field
.
Note
=
types
[
col
]
.
Note
...
...
test/t.yaml
浏览文件 @
24722e8c
...
...
@@ -191,5 +191,5 @@ fields:
# postfix: "\t"
# - field: test
# format: "binary"
# format: "binary
()
"
# postfix: "\t"
\ No newline at end of file
test/test-format.yaml
浏览文件 @
24722e8c
...
...
@@ -12,20 +12,20 @@ fields:
-
field
:
field_format_func_md5
range
:
a-z
format
:
md5
format
:
md5
()
postfix
:
"
\t
"
-
field
:
field_format_func_sha1
range
:
password
format
:
sha1
format
:
sha1
()
postfix
:
"
\t
"
-
field
:
field_format_func_base64
range
:
"
http://zendata.cn?&=word+"
format
:
base64
format
:
base64
()
postfix
:
"
\t
"
-
field
:
field_format_func_urlencode
range
:
"
http://zendata.cn?&=word+"
format
:
urlencode
format
:
urlencode
()
postfix
:
"
\t
"
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录