Преглед изворни кода

prevent double reply of wechat message

master
Patrick Peng Sun пре 8 година
родитељ
комит
6f3fa47148
1 измењених фајлова са 13 додато и 3 уклоњено
  1. +13
    -3
      wechatMsg.go

+ 13
- 3
wechatMsg.go Прегледај датотеку

@@ -1,6 +1,9 @@
package main

import "net/http"
import (
"log"
"net/http"
)

//
//InWechatMsg what we received currently from wechat
@@ -9,9 +12,11 @@ type InWechatMsg struct {
body interface{} //dynamic type
req *http.Request
instantResponse chan string //instance reply channel
replied bool //whether instant response has been replied
}

func (m *InWechatMsg) init() {
m.replied = false
m.instantResponse = make(chan string)
}

@@ -20,12 +25,17 @@ func (m *InWechatMsg) destroy() {
}

func (m *InWechatMsg) replyXML(xml string) {
m.instantResponse <- xml
if !m.replied {
m.replied = true
m.instantResponse <- xml
} else {
log.Println("BUG::doubl reply for wechat message")
}
}

func (m *InWechatMsg) replyText(s string) {
str, _ := BuildTextMsg(m.header.FromUserName, s)
m.instantResponse <- str
m.replyXML(str)
}

func (m *InWechatMsg) transfer2KF() {

Loading…
Откажи
Сачувај