Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
古剑诛仙
soar
提交
cc59f44e
S
soar
项目概览
古剑诛仙
/
soar
与 Fork 源项目一致
Fork自
Xiaomi / soar
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cc59f44e
编写于
2月 14, 2019
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add default dial timeout 3s
上级
dc3b709c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
24 deletion
+47
-24
common/config.go
common/config.go
+31
-12
test/env.bats
test/env.bats
+4
-0
test/fixture/test_Check_the_default_config_of_the_changes.golden
...xture/test_Check_the_default_config_of_the_changes.golden
+6
-6
test/fixture/test_Run_default_printconfig_cases.golden
test/fixture/test_Run_default_printconfig_cases.golden
+6
-6
未找到文件。
common/config.go
浏览文件 @
cc59f44e
...
...
@@ -238,9 +238,9 @@ type Dsn struct {
ServerPubKey
string
`yaml:"server-public-key"`
// Server public key name
MaxAllowedPacket
int
`ymal:"max-allowed-packet"`
// Max packet size allowed
Params
map
[
string
]
string
`yaml:"params"`
// Other Connection parameters, `SET param=val`, `SET NAMES charset`
Timeout
int
`yaml:"timeout"`
// Dial timeout
ReadTimeout
int
`yaml:"read-timeout"`
// I/O read timeout
WriteTimeout
int
`yaml:"write-timeout"`
// I/O write timeout
Timeout
string
`yaml:"timeout"`
// Dial timeout
ReadTimeout
string
`yaml:"read-timeout"`
// I/O read timeout
WriteTimeout
string
`yaml:"write-timeout"`
// I/O write timeout
AllowNativePasswords
bool
`yaml:"allow-native-passwords"`
// Allows the native password authentication method
AllowOldPasswords
bool
`yaml:"allow-old-passwords"`
// Allows the old insecure password method
...
...
@@ -255,6 +255,7 @@ func newDSN(cfg *mysql.Config) *Dsn {
Net
:
"tcp"
,
Schema
:
"information_schema"
,
Charset
:
"utf8"
,
Timeout
:
"3s"
,
AllowNativePasswords
:
true
,
Params
:
make
(
map
[
string
]
string
),
MaxAllowedPacket
:
4
<<
20
,
// 4 MiB
...
...
@@ -282,16 +283,16 @@ func newDSN(cfg *mysql.Config) *Dsn {
dsn
.
MaxAllowedPacket
=
cfg
.
MaxAllowedPacket
dsn
.
ServerPubKey
=
cfg
.
ServerPubKey
dsn
.
TLS
=
cfg
.
TLSConfig
dsn
.
Timeout
=
int
(
cfg
.
Timeout
/
time
.
Second
)
dsn
.
ReadTimeout
=
int
(
cfg
.
ReadTimeout
/
time
.
Second
)
dsn
.
WriteTimeout
=
int
(
cfg
.
WriteTimeout
/
time
.
Second
)
dsn
.
Timeout
=
cfg
.
Timeout
.
String
(
)
dsn
.
ReadTimeout
=
cfg
.
ReadTimeout
.
String
(
)
dsn
.
WriteTimeout
=
cfg
.
WriteTimeout
.
String
(
)
dsn
.
AllowNativePasswords
=
cfg
.
AllowNativePasswords
dsn
.
AllowOldPasswords
=
cfg
.
AllowOldPasswords
return
dsn
}
// newMySQLConfig convert Dsn to go-sql-drive Config
func
(
env
*
Dsn
)
newMySQLCon
if
g
()
(
*
mysql
.
Config
,
error
)
{
func
(
env
*
Dsn
)
newMySQLCon
fi
g
()
(
*
mysql
.
Config
,
error
)
{
var
err
error
dsn
:=
mysql
.
NewConfig
()
...
...
@@ -313,9 +314,18 @@ func (env *Dsn) newMySQLConifg() (*mysql.Config, error) {
dsn
.
MaxAllowedPacket
=
env
.
MaxAllowedPacket
dsn
.
ServerPubKey
=
env
.
ServerPubKey
dsn
.
TLSConfig
=
env
.
TLS
dsn
.
Timeout
=
time
.
Duration
(
env
.
Timeout
)
*
time
.
Second
dsn
.
ReadTimeout
=
time
.
Duration
(
env
.
ReadTimeout
)
*
time
.
Second
dsn
.
WriteTimeout
=
time
.
Duration
(
env
.
WriteTimeout
)
*
time
.
Second
if
env
.
Timeout
!=
""
{
dsn
.
Timeout
,
err
=
time
.
ParseDuration
(
env
.
Timeout
)
LogIfError
(
err
,
"timeout: '%s'"
,
env
.
Timeout
)
}
if
env
.
WriteTimeout
!=
""
{
dsn
.
WriteTimeout
,
err
=
time
.
ParseDuration
(
env
.
WriteTimeout
)
LogIfError
(
err
,
"writeTimeout: '%s'"
,
env
.
WriteTimeout
)
}
if
env
.
ReadTimeout
!=
""
{
dsn
.
ReadTimeout
,
err
=
time
.
ParseDuration
(
env
.
ReadTimeout
)
LogIfError
(
err
,
"readTimeout: '%s'"
,
env
.
ReadTimeout
)
}
dsn
.
AllowNativePasswords
=
env
.
AllowNativePasswords
dsn
.
AllowOldPasswords
=
env
.
AllowOldPasswords
return
dsn
,
err
...
...
@@ -324,7 +334,7 @@ func (env *Dsn) newMySQLConifg() (*mysql.Config, error) {
// 解析命令行DSN输入
func
parseDSN
(
odbc
string
,
d
*
Dsn
)
*
Dsn
{
dsn
:=
newDSN
(
nil
)
var
addr
,
user
,
password
,
schema
,
charset
string
var
addr
,
user
,
password
,
schema
,
charset
,
timeout
string
if
odbc
==
FormatDSN
(
d
)
{
return
d
}
...
...
@@ -336,6 +346,7 @@ func parseDSN(odbc string, d *Dsn) *Dsn {
password
=
d
.
Password
schema
=
d
.
Schema
charset
=
d
.
Charset
timeout
=
d
.
Timeout
}
// 设置为空表示禁用环境
...
...
@@ -398,6 +409,8 @@ func parseDSN(odbc string, d *Dsn) *Dsn {
switch
arg
{
case
"charset"
:
charset
=
val
case
"timeout"
:
timeout
=
val
default
:
}
}
...
...
@@ -414,11 +427,17 @@ func parseDSN(odbc string, d *Dsn) *Dsn {
charset
=
"utf8"
}
// 默认连接数据库超时时间 3s
if
timeout
==
""
{
timeout
=
"3s"
}
dsn
.
Addr
=
addr
dsn
.
User
=
user
dsn
.
Password
=
password
dsn
.
Schema
=
schema
dsn
.
Charset
=
charset
dsn
.
Timeout
=
timeout
return
dsn
}
...
...
@@ -437,7 +456,7 @@ func FormatDSN(env *Dsn) string {
if
env
==
nil
||
env
.
Disable
{
return
""
}
dsn
,
err
:=
env
.
newMySQLCon
if
g
()
dsn
,
err
:=
env
.
newMySQLCon
fi
g
()
if
err
!=
nil
{
return
""
}
...
...
test/env.bats
浏览文件 @
cc59f44e
...
...
@@ -16,3 +16,7 @@ load test_helper
[ $status -eq 0 ]
}
@test "Check dial timeout" {
run timeout 1 ${SOAR_BIN} -test-dsn "1.1.1.1" -check-config
[ $status -eq 124 ]
}
test/fixture/test_Check_the_default_config_of_the_changes.golden
浏览文件 @
cc59f44e
...
...
@@ -12,9 +12,9 @@ online-dsn:
maxallowedpacket: 419437
params:
charset: utf8mb4
timeout: 60
read-timeout: 70
write-timeout: 80
timeout: 60
s
read-timeout: 70
s
write-timeout: 80
s
allow-native-passwords: false
allow-old-passwords: true
disable: false
...
...
@@ -32,9 +32,9 @@ test-dsn:
maxallowedpacket: 4194309
params:
charset: utf8mb4
timeout: 50
read-timeout: 40
write-timeout: 30
timeout: 50
s
read-timeout: 40
s
write-timeout: 30
s
allow-native-passwords: false
allow-old-passwords: true
disable: false
...
...
test/fixture/test_Run_default_printconfig_cases.golden
浏览文件 @
cc59f44e
...
...
@@ -12,9 +12,9 @@ online-dsn:
maxallowedpacket: 4194304
params:
charset: utf8
timeout:
0
read-timeout: 0
write-timeout: 0
timeout:
3s
read-timeout: 0
s
write-timeout: 0
s
allow-native-passwords: true
allow-old-passwords: false
disable: false
...
...
@@ -32,9 +32,9 @@ test-dsn:
maxallowedpacket: 4194304
params:
charset: utf8
timeout:
0
read-timeout: 0
write-timeout: 0
timeout:
3s
read-timeout: 0
s
write-timeout: 0
s
allow-native-passwords: true
allow-old-passwords: false
disable: false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录