forked from micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
94 lines (78 loc) · 1.87 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
94
package client
import (
"github.com/micro/go-micro/broker"
"github.com/micro/go-micro/codec"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport"
)
type options struct {
contentType string
broker broker.Broker
codecs map[string]codec.NewCodec
registry registry.Registry
selector selector.Selector
transport transport.Transport
wrappers []Wrapper
}
type callOptions struct {
selectOptions []selector.SelectOption
}
type publishOptions struct{}
type requestOptions struct {
stream bool
}
// Broker to be used for pub/sub
func Broker(b broker.Broker) Option {
return func(o *options) {
o.broker = b
}
}
// Codec to be used to encode/decode requests for a given content type
func Codec(contentType string, c codec.NewCodec) Option {
return func(o *options) {
o.codecs[contentType] = c
}
}
// Default content type of the client
func ContentType(ct string) Option {
return func(o *options) {
o.contentType = ct
}
}
// Registry to find nodes for a given service
func Registry(r registry.Registry) Option {
return func(o *options) {
o.registry = r
}
}
// Transport to use for communication e.g http, rabbitmq, etc
func Transport(t transport.Transport) Option {
return func(o *options) {
o.transport = t
}
}
// Select is used to select a node to route a request to
func Selector(s selector.Selector) Option {
return func(o *options) {
o.selector = s
}
}
// Adds a Wrapper to a list of options passed into the client
func Wrap(w Wrapper) Option {
return func(o *options) {
o.wrappers = append(o.wrappers, w)
}
}
// Call Options
func WithSelectOption(so selector.SelectOption) CallOption {
return func(o *callOptions) {
o.selectOptions = append(o.selectOptions, so)
}
}
// Request Options
func StreamingRequest() RequestOption {
return func(o *requestOptions) {
o.stream = true
}
}