-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (47 loc) · 910 Bytes
/
config.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
package pool
import(
"time"
)
//default config
const (
defaultInitialSize = 5
defaultMaxSize = 10
defaultExpiryTime = 5*time.Second
defaultAddr string = "127.0.0.1:8080"
defaultMaxIdleNum = 3
)
//pool config
type config struct {
initialSize int
maxSize int
expiryTime time.Duration
addr string
maxIdleNum int
}
//func option
type Options func(*config)
func ConfigInitSize(size int) Options{
return func(c *config) {
c.initialSize = size
}
}
func ConfigMaxSize(size int) Options {
return func(c *config) {
c.maxSize = size
}
}
func ConfigExpiryTime(t time.Duration) Options {
return func(c *config) {
c.expiryTime = t
}
}
func ConfigAddr(addr string) Options {
return func(c *config) {
c.addr = addr
}
}
func ConfigMaxIdleNum(num int) Options {
return func(c *config) {
c.maxIdleNum = num
}
}