-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
76 lines (62 loc) · 1.77 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
package mrpc
import (
"time"
"github.com/dayueba/mrpc/interceptor"
)
type ServerOptions struct {
address string // 监听地址, e.g. :( ip://127.0.0.1:8080、 dns://www.google.com)
timeout time.Duration // timeout
name string
maxConcurrency int
interceptors []interceptor.ServerInterceptor
pluginNames []string // 插件名字
selectorSvrAddr string // 服务发现地址
tracingSvrAddr string // tracing plugin server address, required when using the third-party tracing plugin
tracingSpanName string // tracing span name, required when using the third-party tracing plugin
}
type ServerOption func(*ServerOptions)
func WithAddress(address string) ServerOption {
return func(o *ServerOptions) {
o.address = address
}
}
func WithName(name string) ServerOption {
return func(o *ServerOptions) {
o.name = name
}
}
func WithTimeout(timeout time.Duration) ServerOption {
return func(o *ServerOptions) {
o.timeout = timeout
}
}
func WithMaxConcurrency(maxConcurrency int) ServerOption {
return func(o *ServerOptions) {
o.maxConcurrency = maxConcurrency
}
}
func WithInterceptor(interceptors ...interceptor.ServerInterceptor) ServerOption {
return func(o *ServerOptions) {
o.interceptors = append(o.interceptors, interceptors...)
}
}
func WithPlugin(pluginName ...string) ServerOption {
return func(o *ServerOptions) {
o.pluginNames = append(o.pluginNames, pluginName...)
}
}
func WithSelectorSvrAddr(addr string) ServerOption {
return func(o *ServerOptions) {
o.selectorSvrAddr = addr
}
}
func WithTracingSvrAddr(addr string) ServerOption {
return func(o *ServerOptions) {
o.tracingSvrAddr = addr
}
}
func WithTracingSpanName(name string) ServerOption {
return func(o *ServerOptions) {
o.tracingSpanName = name
}
}