In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is real-time message to build an instant messaging application". The content in this article is simple and clear, and it is easy to learn and understand. let's go deep into the editor's train of thought. Let's study and learn "what is real-time messaging to build an instant messaging application"?
Message client
Before the HTTP section, let's write a mapping map so that all clients listen for messages. Global initialization like this:
New messages created by type MessageClient struct {Messages chan Message UserID string} var messageClients sync.Map
Remember in the previous article, when we created this message, we left a "TODO" comment. From there, we will use this function to schedule a goroutine.
Go messageCreated (message)
Insert this line of code where we left a comment.
Func messageCreated (message Message) error {if err: = db.QueryRow (`SELECT user_id FROM participants WHERE user_id! = $1 and conversation_id = $2`, message.UserID, message.ConversationID). Scan (& message.ReceiverID); err! = nil {return err} go broadcastMessage (message) return nil} func broadcastMessage (message Message) {messageClients.Range (func (key, _ interface {}) bool {client: = key. (* MessageClient) if client.UserID = = message.ReceiverID {client.Messages
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.