move nats local logic

This commit is contained in:
Asim Aslam 2020-01-18 01:29:53 +00:00
parent fd6eb23307
commit 65df711b01

View File

@ -119,17 +119,17 @@ func (n *natsBroker) serve(exit chan bool) error {
// with no address we just default it
// this is a local client address
if len(n.addrs) == 0 || n.local {
if len(n.addrs) == 0 {
host = "127.0.0.1"
port = -1
local = true
// with a local address we parse it
} else {
address := n.addrs[0]
if strings.HasPrefix(address, "nats://") {
address = strings.TrimPrefix(address, "nats://")
}
// check if its a local address and only then embed
if addr.IsLocal(address) {
h, p, err := net.SplitHostPort(address)
if err == nil {
@ -266,10 +266,12 @@ func (n *natsBroker) Connect() error {
// create exit chan
n.exit = make(chan bool)
// start the server if needed
// start embedded server if asked to
if n.local {
if err := n.serve(n.exit); err != nil {
return err
}
}
// set to connected
n.connected = true