forked from vesoft-inc/nebula-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.go
55 lines (50 loc) · 1.61 KB
/
configs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
package nebula_go
import (
"time"
)
// PoolConfig is the configs of connection pool
type PoolConfig struct {
// Socket timeout and Socket connection timeout, unit: seconds
TimeOut time.Duration
// The idleTime of the connection, unit: seconds
// If connection's idle time is longer than idleTime, it will be delete
// 0 value means the connection will not expire
IdleTime time.Duration
// The max connections in pool for all addresses
MaxConnPoolSize int
// The min connections in pool for all addresses
MinConnPoolSize int
}
// validateConf validates config
func (conf *PoolConfig) validateConf(log Logger) {
if conf.TimeOut < 0 {
conf.TimeOut = 0 * time.Millisecond
log.Warn("Illegal Timeout value, the default value of 0 second has been applied")
}
if conf.IdleTime < 0 {
conf.IdleTime = 0 * time.Millisecond
log.Warn("Invalid IdleTime value, the default value of 0 second has been applied")
}
if conf.MaxConnPoolSize < 1 {
conf.MaxConnPoolSize = 10
log.Warn("Invalid MaxConnPoolSize value, the default value of 10 has been applied")
}
if conf.MinConnPoolSize < 0 {
conf.MinConnPoolSize = 0
log.Warn("Invalid MinConnPoolSize value, the default value of 0 has been applied")
}
}
// GetDefaultConf returns the default config
func GetDefaultConf() PoolConfig {
return PoolConfig{
TimeOut: 0 * time.Millisecond,
IdleTime: 0 * time.Millisecond,
MaxConnPoolSize: 10,
MinConnPoolSize: 0,
}
}