July 2019
Intermediate to advanced
502 pages
14h
English
The news service uses the Listen() function from pkg/link_manager_events/listener.go. It accepts the NATS server URL and an event sink that implements the LinkManagerEvents interface. It connects to the NATS server and then subscribes to the link-events subject. This is the same subject that the event sender is sending those events to:
package link_manager_events import ( om "github.com/the-gigi/delinkcious/pkg/object_model" ) func Listen(url string, sink om.LinkManagerEvents) (err error) { conn, err := connect(url) if err != nil { return } conn.Subscribe(subject, func(e *Event) { switch e.EventType { case om.LinkAdded: { sink.OnLinkAdded(e.Username, e.Link) } case om.LinkUpdated: { sink.OnLinkAdded(e.Username, ...