fix initialisation

This commit is contained in:
Asim 2015-05-23 13:13:55 +01:00
parent e6d63d9ff0
commit 8948465b0c

View File

@ -85,15 +85,20 @@ func (n *NatsBroker) Subscribe(topic string, function func(*Message)) (Subscribe
} }
func NewNatsBroker(addrs []string, opts ...Options) Broker { func NewNatsBroker(addrs []string, opts ...Options) Broker {
if len(addrs) == 0 { var cAddrs []string
addrs = []string{nats.DefaultURL} for _, addr := range addrs {
if len(addr) == 0 {
continue
} }
for i, addr := range addrs {
if !strings.HasPrefix(addr, "nats://") { if !strings.HasPrefix(addr, "nats://") {
addrs[i] = "nats://" + addr addr = "nats://" + addr
} }
cAddrs = append(cAddrs, addr)
}
if len(cAddrs) == 0 {
cAddrs = []string{nats.DefaultURL}
} }
return &NatsBroker{ return &NatsBroker{
addrs: addrs, addrs: cAddrs,
} }
} }