From 8948465b0c184119cee71752d0a74e04c3544449 Mon Sep 17 00:00:00 2001 From: Asim Date: Sat, 23 May 2015 13:13:55 +0100 Subject: [PATCH] fix initialisation --- broker/nats_broker.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/broker/nats_broker.go b/broker/nats_broker.go index 9cf75cf0..7ebff133 100644 --- a/broker/nats_broker.go +++ b/broker/nats_broker.go @@ -85,15 +85,20 @@ func (n *NatsBroker) Subscribe(topic string, function func(*Message)) (Subscribe } func NewNatsBroker(addrs []string, opts ...Options) Broker { - if len(addrs) == 0 { - addrs = []string{nats.DefaultURL} - } - for i, addr := range addrs { - if !strings.HasPrefix(addr, "nats://") { - addrs[i] = "nats://" + addr + var cAddrs []string + for _, addr := range addrs { + if len(addr) == 0 { + continue } + if !strings.HasPrefix(addr, "nats://") { + addr = "nats://" + addr + } + cAddrs = append(cAddrs, addr) + } + if len(cAddrs) == 0 { + cAddrs = []string{nats.DefaultURL} } return &NatsBroker{ - addrs: addrs, + addrs: cAddrs, } }