Esempio n. 1
0
func DlmHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	//	db := ConnectDB("./middle.db")
	db := ConnectMySql()

	defer func() {
		db.Close()
		err := recover()
		if err != nil {
			rw.Write(GenJsonpResult(r, &Ret{false, err.(string), nil}))
			log.Println(err)
		}
	}()

	if r.URL.Query().Get("hot_id") != "" {
		LogClient(r.RemoteAddr, GetParameter(r, "hot_id"), db)
	}

	switcher := sw.Dispatch(db)
	var ret []byte
	if Authorize(r) {
		msg, data := switcher[sw.GetParameter(r, "cmd")](r)
		log.Println("rth4")
		ret = GenJsonpResult(r, &Ret{true, msg, data})
	} else {
		panic("Not authorized!")
	}
	rw.Write(ret)
}
Esempio n. 2
0
// 得到指定模块的业务逻辑处理函数
func GetModuleSwitcher(moduleName string, db *sql.DB) sw.Dlm {
	var switcher sw.Dlm
	switch moduleName {
	case "votes":
		switcher = sw.VoteDispatch(db)
		//case "quiz":
		//	switcher = sw.QuizDispatch(db)
	case "choices":
		switcher = sw.VoteDispatch(db)
	case "jssdk":
		switcher = sw.JssdkDispatch(db)
	case "videos":
		switcher = sw.VideoDispatch(db)
	default:
		switcher = sw.Dispatch(db)
	}
	return switcher
}