diff options
author | Wolfy-J <[email protected]> | 2018-06-11 11:28:24 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 11:28:24 +0300 |
commit | 2f135b359575cc1625d1461bb6d8e478da8ccf54 (patch) | |
tree | 8561f84318c3a291f4a38df6b347954bda777e41 /service/rpc/config.go | |
parent | 6efaa0aa951240c2bb643761f103ee3f0fafb4d9 (diff) |
refactor
Diffstat (limited to 'service/rpc/config.go')
-rw-r--r-- | service/rpc/config.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/service/rpc/config.go b/service/rpc/config.go new file mode 100644 index 00000000..06d63d65 --- /dev/null +++ b/service/rpc/config.go @@ -0,0 +1,35 @@ +package rpc + +import ( + "errors" + "net" + "strings" +) + +type config struct { + // Indicates if RPC connection is enabled. + Enable bool + + // AddListener string + Listen string +} + +// listener creates new rpc socket listener. +func (cfg *config) listener() (net.Listener, error) { + dsn := strings.Split(cfg.Listen, "://") + if len(dsn) != 2 { + return nil, errors.New("invalid socket DSN (tcp://:6001, unix://rpc.sock)") + } + + return net.Listen(dsn[0], dsn[1]) +} + +// dialer creates rpc socket dialer. +func (cfg *config) dialer() (net.Conn, error) { + dsn := strings.Split(cfg.Listen, "://") + if len(dsn) != 2 { + return nil, errors.New("invalid socket DSN (tcp://:6001, unix://rpc.sock)") + } + + return net.Dial(dsn[0], dsn[1]) +} |