From ef469a5c26ea91a8a212fc6a61dc5eff98c27c63 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Mon, 29 May 2017 21:16:08 +1000 Subject: [PATCH] server simplified to use pipelines --- server.go | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/server.go b/server.go index 4c39541..4984845 100644 --- a/server.go +++ b/server.go @@ -10,7 +10,6 @@ import ( "net/http/httputil" "net/url" "os" - "reflect" "sort" "strings" ) @@ -66,33 +65,16 @@ type InWechatMsg struct { //answerWechatPost distribute PostRequest according to xml body info func answerWechatPost(w http.ResponseWriter, r *http.Request) { in, valid := readWechatInput(r) - //reply := "" //nothing + reply := "" //nothing + w.Header().Set("Content-Type", "text/xml; charset=utf-8") + if !valid { log.Println("Error: Invalid Input ") + } else { + //put into user session based pipeline + AllInMessage <- in } - - AllInMessage <- in - - openID := in.header.FromUserName - if openID == "" { - log.Println("nothing") - } - - //dummy reply - reply, _ := BuildTextMsg(openID, "澳") - w.Header().Set("Content-Type", "text/xml; charset=utf-8") fmt.Fprint(w, reply) - - //time.Sleep(5 * time.Second) - v := reflect.ValueOf(answerWechatPost) - log.Printf("Current Pointer: %d", v.Pointer()) - //debug.PrintStack() - - //load session into memory - // session := startSession(openID, in, w, r) //who , input what? - // session.ProcessInput() - // //put session back to disk - // session.Save() } // func (session) ProcessInput(w, r) {