Don't panic if no NATS server is configured for clustering
This commit is contained in:
parent
8aa7fe1a49
commit
ae81e484d3
13
cluster.go
13
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()))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue