go-pattern-examples/gomore/27_messages/message_queue.go
2020-04-30 14:50:21 +08:00

18 lines
439 B
Go

package messaging
//Queue hold all topics
type Queue struct {
Topics map[string]Topic //topic ID<-----> topic Object
}
//AddTopic to Queue
func (q *Queue) AddTopic(topicName string, topicUserQueueSize int) Topic {
if q.Topics == nil {
q.Topics = make(map[string]Topic)
}
if _, found := q.Topics[topicName]; !found {
q.Topics[topicName] = Topic{UserQueueSize: topicUserQueueSize, Name: topicName}
}
return q.Topics[topicName]
}