Pass client to more of the runtime
This commit is contained in:
@@ -3,6 +3,8 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
)
|
||||
|
||||
// Options contains configuration for the Store
|
||||
@@ -17,6 +19,8 @@ type Options struct {
|
||||
Table string
|
||||
// Context should contain all implementation specific options, using context.WithValue.
|
||||
Context context.Context
|
||||
// Client to use for RPC
|
||||
Client client.Client
|
||||
}
|
||||
|
||||
// Option sets values in Options
|
||||
@@ -52,6 +56,13 @@ func WithContext(c context.Context) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithClient sets the stores client to use for RPC
|
||||
func WithClient(c client.Client) Option {
|
||||
return func(o *Options) {
|
||||
o.Client = c
|
||||
}
|
||||
}
|
||||
|
||||
// ReadOptions configures an individual Read operation
|
||||
type ReadOptions struct {
|
||||
Database, Table string
|
||||
|
@@ -219,12 +219,16 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if options.Client == nil {
|
||||
options.Client = client.DefaultClient
|
||||
}
|
||||
|
||||
service := &serviceStore{
|
||||
options: options,
|
||||
Database: options.Database,
|
||||
Table: options.Table,
|
||||
Nodes: options.Nodes,
|
||||
Client: pb.NewStoreService("go.micro.store", client.DefaultClient),
|
||||
Client: pb.NewStoreService("go.micro.store", options.Client),
|
||||
}
|
||||
|
||||
return service
|
||||
|
Reference in New Issue
Block a user