summaryrefslogtreecommitdiff
path: root/internal/rpc/client.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-01-15 12:08:20 +0300
committerValery Piashchynski <[email protected]>2022-01-15 12:08:20 +0300
commit5254c8eb27311e2a8a53a4c90c3829cf1238c563 (patch)
treeb51c9a4c1dd4c25adc511498ce0380a7078c5572 /internal/rpc/client.go
parent13609dd03dd0d2fa85b9fb850be787bf4e2ea67f (diff)
Repository content update
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/rpc/client.go')
-rw-r--r--internal/rpc/client.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/rpc/client.go b/internal/rpc/client.go
new file mode 100644
index 00000000..f371a51c
--- /dev/null
+++ b/internal/rpc/client.go
@@ -0,0 +1,33 @@
+// Package prc contains wrapper around RPC client ONLY for internal usage.
+package rpc
+
+import (
+ "net/rpc"
+
+ "github.com/spiral/errors"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
+ "github.com/spiral/roadrunner-plugins/v2/config"
+ rpcPlugin "github.com/spiral/roadrunner-plugins/v2/rpc"
+)
+
+// NewClient creates client ONLY for internal usage (communication between our application with RR side).
+// Client will be connected to the RPC.
+func NewClient(cfgPlugin *config.Plugin) (*rpc.Client, error) {
+ if !cfgPlugin.Has(rpcPlugin.PluginName) {
+ return nil, errors.E("rpc service disabled")
+ }
+
+ rpcConfig := &rpcPlugin.Config{}
+ if err := cfgPlugin.UnmarshalKey(rpcPlugin.PluginName, rpcConfig); err != nil {
+ return nil, err
+ }
+
+ rpcConfig.InitDefaults()
+
+ conn, err := rpcConfig.Dialer()
+ if err != nil {
+ return nil, err
+ }
+
+ return rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)), nil
+}