summaryrefslogtreecommitdiff
path: root/service/rpc.go
blob: eb128768d4e41921f955222a55f28cd60ca61062 (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
package service

import (
	"net"
	"strings"
)

type RPCConfig struct {
	Listen string
}

func (cfg *RPCConfig) CreateListener() (net.Listener, error) {
	dsn := strings.Split(cfg.Listen, "://")
	if len(dsn) != 2 {
		return nil, dsnError
	}

	return net.Listen(dsn[0], dsn[1])
}

func (cfg *RPCConfig) CreateDialer() (net.Conn, error) {
	dsn := strings.Split(cfg.Listen, "://")
	if len(dsn) != 2 {
		return nil, dsnError
	}

	return net.Dial(dsn[0], dsn[1])
}

func NewBus() *Bus {
	return &Bus{services: make([]Service, 0)}
}