diff --git a/cluster.go b/cluster.go index 76bdb2b..19e3a96 100644 --- a/cluster.go +++ b/cluster.go @@ -16,9 +16,9 @@ type ClusterConnector struct { subs map[string]*nats.Subscription } -func NewClusterConnector(servers string, ssl bool) *ClusterConnector { +func NewClusterConnector(urls string, ssl bool) *ClusterConnector { opts := nats.DefaultOptions - opts.Servers = strings.Split(servers, ",") + opts.Servers = strings.Split(urls, ",") for i, s := range opts.Servers { opts.Servers[i] = strings.Trim(s, " ") } @@ -32,6 +32,9 @@ func NewClusterConnector(servers string, ssl bool) *ClusterConnector { } func (cc *ClusterConnector) Subscribe(subj string, ch chan *irc.Message) { + if cc.conn == nil { + return + } if _, exists := cc.subs[subj]; exists { return } @@ -47,6 +50,9 @@ func (cc *ClusterConnector) Subscribe(subj string, ch chan *irc.Message) { } func (cc *ClusterConnector) Unsubscribe(subj string) { + if cc.conn == nil { + return + } if sub, exists := cc.subs[subj]; exists { sub.Unsubscribe() delete(cc.subs, subj) @@ -54,6 +60,9 @@ func (cc *ClusterConnector) Unsubscribe(subj string) { } func (cc *ClusterConnector) Publish(msg *irc.Message) { + if cc.conn == nil { + return + } subj := strings.ToLower(msg.Args[0]) cc.conn.Publish(subj, []byte(msg.String())) }