init subscription map if nil

This commit is contained in:
kiwiidb
2022-04-07 11:31:10 +02:00
parent a5ae01a5f2
commit 55ee968174

View File

@@ -20,7 +20,9 @@ func NewPubsub() *Pubsub {
func (ps *Pubsub) Subscribe(id string, topic int64, ch chan models.Invoice) {
ps.mu.Lock()
defer ps.mu.Unlock()
if ps.subs[topic] == nil {
ps.subs[topic] = make(map[string]chan models.Invoice)
}
ps.subs[topic][id] = ch
}