forked from go-micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
50 lines (39 loc) · 860 Bytes
/
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
package source
import (
"context"
"github.com/justcy/go-micro/v4/client"
"github.com/justcy/go-micro/v4/config/encoder"
"github.com/justcy/go-micro/v4/config/encoder/json"
)
type Options struct {
// Encoder
Encoder encoder.Encoder
// for alternative data
Context context.Context
// Client to use for RPC
Client client.Client
}
type Option func(o *Options)
func NewOptions(opts ...Option) Options {
options := Options{
Encoder: json.NewEncoder(),
Context: context.Background(),
Client: client.DefaultClient,
}
for _, o := range opts {
o(&options)
}
return options
}
// WithEncoder sets the source encoder.
func WithEncoder(e encoder.Encoder) Option {
return func(o *Options) {
o.Encoder = e
}
}
// WithClient sets the source client.
func WithClient(c client.Client) Option {
return func(o *Options) {
o.Client = c
}
}