-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlb_cfg_opt.go
107 lines (92 loc) · 2.44 KB
/
lb_cfg_opt.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package lb_client
import (
"time"
)
//配置选项
type LbCfgOption struct {
LbStrategy int //负载策略(必传)
ZkServerList []string //zk列表(必传)
ZkConnTimeOut time.Duration //zk连接超时
Root string //根目录
RouterType string //路由类型(如:iat、tts)(必传)
SubRouterTypes []string //子路由类型列表(如:[iat_gray,iat_hefei])(必传)
RedisHost string //redis主机(必传)
RedisPasswd string //redis密码
MaxActive int //redis最大连接数(maxActive=0代表没连接限制)
MaxIdle int //redis最大空闲实例数
Db int //redis数据库
IdleTimeOut time.Duration //redis空闲实例超时设置(单位:s)
}
type LbCfgOpt func(*LbCfgOption)
//配置负载的策略
func WithLbStrategy(strategy int) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.LbStrategy = strategy
}
}
//配置zk列表
func WithZkList(zkList []string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.ZkServerList = zkList
}
}
//配置zk连接超时时间
func WithZkConnTimeOut(timeout time.Duration) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.ZkConnTimeOut = timeout
}
}
//配置根目录
func WithRoot(root string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.Root = root
}
}
//配置路由类型(业务类型)
func WithRouterType(routerType string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.RouterType = routerType
}
}
//配置子路由类型
func WithSubRouterTypes(subRouterType []string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.SubRouterTypes = subRouterType
}
}
//配置redis主机
func WithRedisHost(redisHost string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.RedisHost = redisHost
}
}
//配置redis主机密码
func WithRedisPassword(redisPwd string) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.RedisPasswd = redisPwd
}
}
//配置redis数据库
func WithRedisDb(db int) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.Db = db
}
}
//配置redis最大连接数
func WithRedisMaxActive(maxActive int) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.MaxActive = maxActive
}
}
//配置redis最大空闲连接数
func WithRedisMaxIdle(maxIdle int) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.MaxIdle = maxIdle
}
}
//配置redis空闲连接超时
func WithRedisIdleTimeOut(idleTimeOut time.Duration) LbCfgOpt {
return func(lc *LbCfgOption) {
lc.IdleTimeOut = idleTimeOut
}
}