summaryrefslogtreecommitdiff
path: root/plugins/rpc/config.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-25 16:18:26 +0300
committerGitHub <[email protected]>2021-01-25 16:18:26 +0300
commitf1875f5715bf7635e17697ae3513ba3d21e4e524 (patch)
treef9c0c3876ef542217a8bd7ff17f90bffc018132f /plugins/rpc/config.go
parenta063ad05b1cab8ec71eecc32f836efa4d431c6b8 (diff)
parent99bf203511b8af4be37186017e2e0c73a030d4f3 (diff)
Merge pull request #429 from spiral/2.0
Release 2.0-dev
Diffstat (limited to 'plugins/rpc/config.go')
-rw-r--r--plugins/rpc/config.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/rpc/config.go b/plugins/rpc/config.go
new file mode 100644
index 00000000..88ad7f0e
--- /dev/null
+++ b/plugins/rpc/config.go
@@ -0,0 +1,46 @@
+package rpc
+
+import (
+ "errors"
+ "net"
+ "strings"
+
+ "github.com/spiral/roadrunner/v2/utils"
+)
+
+// Config defines RPC service config.
+type Config struct {
+ // Listen string
+ Listen string
+}
+
+// InitDefaults allows to init blank config with pre-defined set of default values.
+func (c *Config) InitDefaults() {
+ if c.Listen == "" {
+ c.Listen = "tcp://127.0.0.1:6001"
+ }
+}
+
+// Valid returns nil if config is valid.
+func (c *Config) Valid() error {
+ if dsn := strings.Split(c.Listen, "://"); len(dsn) != 2 {
+ return errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)")
+ }
+
+ return nil
+}
+
+// Listener creates new rpc socket Listener.
+func (c *Config) Listener() (net.Listener, error) {
+ return utils.CreateListener(c.Listen)
+}
+
+// Dialer creates rpc socket Dialer.
+func (c *Config) Dialer() (net.Conn, error) {
+ dsn := strings.Split(c.Listen, "://")
+ if len(dsn) != 2 {
+ return nil, errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)")
+ }
+
+ return net.Dial(dsn[0], dsn[1])
+}