forked from lubanproj/gorpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
executable file
·84 lines (69 loc) · 2.21 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
77
78
79
80
81
82
83
84
package gorpc
import (
"time"
"github.com/lubanproj/gorpc/interceptor"
)
// ServerOptions defines the server serve parameters
type ServerOptions struct {
address string // 监听地址 例子 :( ip://127.0.0.1:8080、 dns://www.google.com)
network string // 网络类型 例子 : tcp、udp
protocol string // 协议 例子 : proto、json
timeout time.Duration // 超时时间 timeout
serializationType string // 序列化类型 , default: proto
selectorSvrAddr string // service discovery server address, required when using the third-party service discovery plugin
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
pluginNames []string // plugin name
interceptors []interceptor.ServerInterceptor
}
type ServerOption func(*ServerOptions)
func WithAddress(address string) ServerOption {
return func(o *ServerOptions) {
o.address = address
}
}
func WithNetwork(network string) ServerOption {
return func(o *ServerOptions) {
o.network = network
}
}
func WithProtocol(protocol string) ServerOption {
return func(o *ServerOptions) {
o.protocol = protocol
}
}
func WithTimeout(timeout time.Duration) ServerOption {
return func(o *ServerOptions) {
o.timeout = timeout
}
}
func WithSerializationType(serializationType string) ServerOption {
return func(o *ServerOptions) {
o.serializationType = serializationType
}
}
func WithSelectorSvrAddr(addr string) ServerOption {
return func(o *ServerOptions) {
o.selectorSvrAddr = addr
}
}
func WithPlugin(pluginName ...string) ServerOption {
return func(o *ServerOptions) {
o.pluginNames = append(o.pluginNames, pluginName...)
}
}
func WithInterceptor(interceptors ...interceptor.ServerInterceptor) ServerOption {
return func(o *ServerOptions) {
o.interceptors = append(o.interceptors, interceptors...)
}
}
func WithTracingSvrAddr(addr string) ServerOption {
return func(o *ServerOptions) {
o.tracingSvrAddr = addr
}
}
func WithTracingSpanName(name string) ServerOption {
return func(o *ServerOptions) {
o.tracingSpanName = name
}
}