forked from evolutek/cellaserv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.go
46 lines (36 loc) · 999 Bytes
/
publish.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bitbucket.org/evolutek/cellaserv2-protobuf"
"net"
"path/filepath"
"strings"
)
func handlePublish(conn net.Conn, msgBytes []byte, pub *cellaserv.Publish) {
log.Info("[Publish] %s publishes %s", connDescribe(conn), *pub.Event)
doPublish(msgBytes, pub)
}
func doPublish(msgBytes []byte, pub *cellaserv.Publish) {
event := *pub.Event
// Logging
log.Debug("[Publish] Publishing %s", event)
// Handle log publishes
if strings.HasPrefix(event, "log.") {
cellaservLog(pub)
}
var subs []net.Conn
// Handle glob susbscribers
for pattern, cons := range subscriberMatchMap {
matched, _ := filepath.Match(pattern, event)
if matched {
subs = append(subs, cons...)
}
}
// Add exact matches
subs = append(subs, subscriberMap[event]...)
for _, connSub := range subs {
log.Debug("[Publish] Forwarding publish to %s", connDescribe(connSub))
dumpOutgoing(connSub, msgBytes)
sendRawMessage(connSub, msgBytes)
}
}
// vim: set nowrap tw=100 noet sw=8: