-
Notifications
You must be signed in to change notification settings - Fork 93
/
options.go
93 lines (78 loc) · 2.53 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
85
86
87
88
89
90
91
92
93
package kafka
import (
"crypto/tls"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"github.com/tx7do/kratos-transport/broker"
"github.com/tx7do/kratos-transport/broker/kafka"
)
type ServerOption func(o *Server)
// WithBrokerOptions MQ代理配置
func WithBrokerOptions(opts ...broker.Option) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, opts...)
}
}
// WithAddress MQ代理地址
func WithAddress(addrs []string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithAddress(addrs...))
}
}
// WithTLSConfig TLS配置
func WithTLSConfig(c *tls.Config) ServerOption {
return func(s *Server) {
if c != nil {
s.brokerOpts = append(s.brokerOpts, broker.WithEnableSecure(true))
}
s.brokerOpts = append(s.brokerOpts, broker.WithTLSConfig(c))
}
}
// WithCodec 编解码器
func WithCodec(c string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithCodec(c))
}
}
// WithEnableKeepAlive enable keep alive
func WithEnableKeepAlive(enable bool) ServerOption {
return func(s *Server) {
s.enableKeepAlive = enable
}
}
// WithPlainMechanism PLAIN认证信息
func WithPlainMechanism(username, password string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, kafka.WithPlainMechanism(username, password))
}
}
// WithScramMechanism SCRAM认证信息
func WithScramMechanism(algo string, username, password string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, kafka.WithScramMechanism(kafka.ScramAlgorithm(algo), username, password))
}
}
// WithGlobalTracerProvider 注入全局的链路追踪器的Provider
func WithGlobalTracerProvider() ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithGlobalTracerProvider())
}
}
// WithGlobalPropagator 注入全局的链路追踪器的Propagator
func WithGlobalPropagator() ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithGlobalPropagator())
}
}
// WithTracerProvider 注入链路追踪器的Provider
func WithTracerProvider(provider trace.TracerProvider, tracerName string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithTracerProvider(provider, tracerName))
}
}
// WithPropagator 注入链路追踪器的Propagator
func WithPropagator(propagators propagation.TextMapPropagator) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithPropagator(propagators))
}
}