First of all, I want to make Long Polling notification system. To be more specific, I will make http request, and response will be returned only if map channel is true
.
This is the code block I used:
var MessageNotification = make(map[string]chan bool, 10)
func GetNotification(id int, timestamp int) notification {
<-MessageNotification["1"]
var chat_services []*models.Chat_service
o := orm.NewOrm()
_, err := o.QueryTable("chat_service").Filter("Sender__id", id).RelatedSel().All(&chat_services)
if err != nil {
return notification{Status: false}
}
return notification{Status: true, MessageList: chat_services}
}
func SetNotification(id int) {
MessageNotification[strconv.Itoa(id)] <- true
}
This is controller block :
func (c *ChatController) Notification() {
data := chat.GetNotification(1,0)
c.Data["json"] = data
c.ServeJSON()
}
func (c *ChatController) Websocket(){
chat.SetNotification(1)
c.Data["json"] = "test"
c.ServeJSON();
}
function names and variable created for test.
No error occurred. Thanks for your help.