summaryrefslogtreecommitdiff
path: root/service/rpc/config.go
blob: 06d63d6551ae931aa811f2ea354202777f9fafee (plain)
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
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])
}