move nats local logic
This commit is contained in:
parent
fd6eb23307
commit
65df711b01
@ -119,17 +119,17 @@ func (n *natsBroker) serve(exit chan bool) error {
|
|||||||
|
|
||||||
// with no address we just default it
|
// with no address we just default it
|
||||||
// this is a local client address
|
// this is a local client address
|
||||||
if len(n.addrs) == 0 || n.local {
|
if len(n.addrs) == 0 {
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
port = -1
|
port = -1
|
||||||
local = true
|
local = true
|
||||||
// with a local address we parse it
|
|
||||||
} else {
|
} else {
|
||||||
address := n.addrs[0]
|
address := n.addrs[0]
|
||||||
if strings.HasPrefix(address, "nats://") {
|
if strings.HasPrefix(address, "nats://") {
|
||||||
address = strings.TrimPrefix(address, "nats://")
|
address = strings.TrimPrefix(address, "nats://")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if its a local address and only then embed
|
||||||
if addr.IsLocal(address) {
|
if addr.IsLocal(address) {
|
||||||
h, p, err := net.SplitHostPort(address)
|
h, p, err := net.SplitHostPort(address)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -266,10 +266,12 @@ func (n *natsBroker) Connect() error {
|
|||||||
// create exit chan
|
// create exit chan
|
||||||
n.exit = make(chan bool)
|
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 {
|
if err := n.serve(n.exit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set to connected
|
// set to connected
|
||||||
n.connected = true
|
n.connected = true
|
||||||
|
Loading…
Reference in New Issue
Block a user