本文整理匯總了Golang中github.com/nyxtom/broadcast/server.ProtocolClient.Address方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolClient.Address方法的具體用法?Golang ProtocolClient.Address怎麽用?Golang ProtocolClient.Address使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nyxtom/broadcast/server.ProtocolClient
的用法示例。
在下文中一共展示了ProtocolClient.Address方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: subscribe
// subscribe will add the given protocol client to the channel to subscribe to
func (b *PubSubBackend) subscribe(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 1 {
return nil
} else {
for _, k := range d {
key := string(k)
if topic, ok := b.topics[key]; ok {
topic.Lock()
id := client.Address()
if _, ok = topic.clients[id]; !ok {
topic.clients[id] = empty
topic.size++
}
topic.Unlock()
} else {
topic := new(TopicChannel)
topic.clients = make(map[string]struct{})
topic.size = 1
topic.clients[client.Address()] = empty
b.topics[key] = topic
}
}
return nil
}
}
示例2: unsubscribe
func (b *PubSubBackend) unsubscribe(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 1 {
return nil
} else {
for _, k := range d {
key := string(k)
if topic, ok := b.topics[key]; ok {
topic.Lock()
id := client.Address()
if _, ok = topic.clients[id]; ok {
delete(topic.clients, id)
topic.size--
}
topic.Unlock()
}
}
return nil
}
}