Various fixes in cluster.go
This commit is contained in:
parent
9e6de5ac37
commit
262da96e46
19
cluster.go
19
cluster.go
|
@ -1,4 +1,3 @@
|
||||||
could not parse "irc.go": /home/an/src/iqcomm_/src/irc/irc.go:128:20: expected boolean expression, found simple statement (missing parentheses around composite literal?)
|
|
||||||
// vim:ts=4:sts=4:sw=4:noet:tw=72
|
// vim:ts=4:sts=4:sw=4:noet:tw=72
|
||||||
|
|
||||||
package ircd
|
package ircd
|
||||||
|
@ -16,7 +15,7 @@ type ClusterConnector struct {
|
||||||
subs map[string]*nats.Subscription
|
subs map[string]*nats.Subscription
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClusterConnector(servers string, ssl bool) *NatsConnector {
|
func NewClusterConnector(servers string, ssl bool) *ClusterConnector {
|
||||||
opts := nats.DefaultOptions
|
opts := nats.DefaultOptions
|
||||||
opts.Servers = strings.Split(servers, ",")
|
opts.Servers = strings.Split(servers, ",")
|
||||||
for i, s := range opts.Servers {
|
for i, s := range opts.Servers {
|
||||||
|
@ -28,29 +27,31 @@ func NewClusterConnector(servers string, ssl bool) *NatsConnector {
|
||||||
// foo
|
// foo
|
||||||
}
|
}
|
||||||
subs := make(map[string]*nats.Subscription)
|
subs := make(map[string]*nats.Subscription)
|
||||||
return &NatsConnector{conn: conn, subs: subs}
|
return &ClusterConnector{conn: conn, subs: subs}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ClusterConnector) Subscribe(subj string, ch chan *irc.Message) {
|
func (cc *ClusterConnector) Subscribe(subj string, ch chan *irc.Message) {
|
||||||
if _, exists := c.subs[subj]; exists {
|
if _, exists := cc.subs[subj]; exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sub, err := c.natsConn.Subscribe(subj, func(n *nats.Msg) {
|
sub, err := cc.conn.Subscribe(subj, func(n *nats.Msg) {
|
||||||
m := irc.Parse(string(n.Data))
|
m := irc.Parse(string(n.Data))
|
||||||
ch <- m
|
ch <- m
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.subs[subj] = sub
|
cc.subs[subj] = sub
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ClusterConnector) Unsubscribe(subj string) {
|
func (cc *ClusterConnector) Unsubscribe(subj string) {
|
||||||
cc.conn.Unsubscribe(subj)
|
if sub, exists := cc.subs[subj]; exists {
|
||||||
delete(cc.subs, subj)
|
sub.Unsubscribe()
|
||||||
|
delete(cc.subs, subj)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ClusterConnector) Publish(msg *irc.Message) {
|
func (cc *ClusterConnector) Publish(msg *irc.Message) {
|
||||||
subj := strings.ToLower(msg.Pre)
|
subj := strings.ToLower(msg.Pre)
|
||||||
cc.conn.Publish(subj, []bytes(msg.String()))
|
cc.conn.Publish(subj, []byte(msg.String()))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue