/
server_options.go
65 lines (54 loc) · 1.63 KB
/
server_options.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
package mq
import (
"time"
"github.com/go-kratos/kratos/v2/middleware"
)
type ServerOptionFunc func(*serverOptions)
// ServerOptionWithTimeout 超时控制
func ServerOptionWithTimeout(duration time.Duration) ServerOptionFunc {
return func(options *serverOptions) {
options.timeout = duration
}
}
// ServerOptionWithMiddleware 中间件
func ServerOptionWithMiddleware(ms ...middleware.Middleware) ServerOptionFunc {
return func(options *serverOptions) {
options.ms = ms
}
}
// ServerOptionWithDecodeFunc 解码函数
func ServerOptionWithDecodeFunc(f DecodeFunc) ServerOptionFunc {
return func(options *serverOptions) {
options.decodeFunc = f
}
}
// ServerOptionWithErrHandler 运行错误处理器
func ServerOptionWithErrHandler(handler ErrorHandler) ServerOptionFunc {
return func(options *serverOptions) {
options.errHandler = handler
}
}
// ServerOptionWithErrHandleFunc 运行错误处理函数
func ServerOptionWithErrHandleFunc(f ErrorHandlerFunc) ServerOptionFunc {
return func(options *serverOptions) {
options.errHandler = f
}
}
// ServerOptionWithServerName 服务名定义
func ServerOptionWithServerName(name string) ServerOptionFunc {
return func(options *serverOptions) {
options.serverName = name
}
}
// ServerOptionWithConcurrencyNum 并发数
func ServerOptionWithConcurrencyNum(num int32) ServerOptionFunc {
return func(options *serverOptions) {
options.cap = num
}
}
// ServerOptionWithScaleThreshold 阈值 任务队列长度超过 这个数字 则会增加 go routine
func ServerOptionWithScaleThreshold(num int32) ServerOptionFunc {
return func(options *serverOptions) {
options.scaleThreshold = num
}
}