2019-05-31 01:11:13 +03:00
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/client"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/json"
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
// Encoder
|
|
|
|
Encoder encoder.Encoder
|
|
|
|
|
|
|
|
// for alternative data
|
|
|
|
Context context.Context
|
2020-05-11 19:57:39 +03:00
|
|
|
|
|
|
|
// Client to use for RPC
|
|
|
|
Client client.Client
|
2019-05-31 01:11:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
options := Options{
|
|
|
|
Encoder: json.NewEncoder(),
|
|
|
|
Context: context.Background(),
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 19:57:39 +03:00
|
|
|
|
|
|
|
// WithClient sets the source client
|
|
|
|
func WithClient(c client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Client = c
|
|
|
|
}
|
|
|
|
}
|