forked from go-chassis/go-chassis
/
rpc_invoker.go
executable file
·48 lines (41 loc) · 1.14 KB
/
rpc_invoker.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
package core
import (
"context"
"sync"
"github.com/go-chassis/go-chassis/core/common"
"github.com/go-chassis/go-chassis/core/invocation"
)
// RPCInvoker is rpc invoker
//one invoker for one microservice
//thread safe
type RPCInvoker struct {
*abstractInvoker
sync.RWMutex
}
// NewRPCInvoker is gives the object of rpc invoker
func NewRPCInvoker(opt ...Option) *RPCInvoker {
opts := newOptions(opt...)
ri := &RPCInvoker{
abstractInvoker: &abstractInvoker{
opts: opts,
},
}
//clientPluginName := os.Getenv("rpc_client_plugin")
//clientF := client.GetClientNewFunc(clientPluginName)
return ri
}
// Invoke is for to invoke the functions during API calls
func (ri *RPCInvoker) Invoke(ctx context.Context, microServiceName, schemaID, operationID string, arg interface{}, reply interface{}, options ...InvocationOption) error {
opts := getOpts(microServiceName, options...)
if opts.Protocol == "" {
opts.Protocol = common.ProtocolHighway
}
i := invocation.New(ctx)
wrapInvocationWithOpts(i, opts)
i.MicroServiceName = microServiceName
i.SchemaID = schemaID
i.OperationID = operationID
i.Args = arg
i.Reply = reply
return ri.invoke(i)
}