package main import ( "os" ) type chatProcedureID struct { chatprocID string } func (m *chatProcedureID) setID(id string) { m.chatprocID = id } func (m *chatProcedureID) getID() string { return m.chatprocID } // a description of type chatProcedure interface { setID(id string) //set Procedure ID getID() (id string) //get Proecdure ID init(*openIDSessionData) //house keeping clean(*openIDSessionData) //house keeping start(*openIDSessionData, *InWechatMsg) //for first message serve(*openIDSessionData, *InWechatMsg) bool //for all subsequent message summary(*openIDSessionData) //after all message has been done intro(*openIDSessionData, *InWechatMsg) //initial text/video/voice introduction } //AllProc all procedure that we implemented var AllProc = map[string]chatProcedure{} func initAllProc() { //registerProc("Dummy", &procDummy) registerProc("Echo", &procEcho) registerProc("用户信息", &procGetBasicUserInfo) registerProc("搜索校友", &procSearchMember) registerProc("投诉反馈", &procFeedback) } func registerProc(id string, proc chatProcedure) { AllProc[id] = proc proc.setID(id) } func getProcedurePath(openID, ProcedureName string) (path string) { path = procedureDir + string(os.PathSeparator) + ProcedureName + string(os.PathSeparator) + openID + ".json" ensurePathExist(path) return }