Example #1
0
func (bb *BrowseBusiness) JokeListRandom(idstr string) ReturnInfo {
	resInfo := ReturnInfo{}
	ids := make([]string, 0)
	idarry := strings.Split(idstr, ",")
	for i := 0; i < len(idarry); i++ {
		id, _ := strconv.Atoi(idarry[i])
		if id > 0 {
			ids = append(ids, idarry[i])
		}
		if i >= (ContentListPageSize - 1) {
			break
		}
	}
	idss := strings.Join(ids, ",")
	objs := make([]models.JokeTb, 0)
	err := bb.OrmEngine.Where(fmt.Sprintf("Id in(%s)", idss)).Find(&objs)
	if err != nil {
		resInfo.Status = ReturnException
		common.LogError(fmt.Sprintf("JokeList:%v", err))
		return resInfo
	} else {
		count, _ := bb.OrmEngine.Count(&models.JokeTb{})
		resInfo.Recordcount = int(count)
		resInfo.Data = objs
		resInfo.Status = ReturnSuccess
	}
	return resInfo
}
Example #2
0
func recoverAction() {
	if err := recover(); err != nil {
		pc, _, line, _ := runtime.Caller(4)
		actionName := runtime.FuncForPC(pc).Name()
		common.LogInfo(actionName + " end")
		common.LogError(fmt.Sprintf("actionName:%s line:%d, err:%v ", actionName, line, err))
	}
}
Example #3
0
func main() {
	defer recoverapp()

	mux := http.NewServeMux()
	mux.HandleFunc("/", controller.HandlerCore)
	s := &http.Server{
		Addr:           fmt.Sprintf(":%d", controller.Configtools.HttpPort),
		Handler:        mux,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	common.LogInfo("web start", controller.Configtools.HttpPort)
	common.LogError(s.ListenAndServe())
}
Example #4
0
func (bb *BrowseBusiness) JokeList(pageindex int) ReturnInfo {
	resInfo := ReturnInfo{}
	objs := make([]models.JokeTb, 0)
	err := bb.OrmEngine.Desc("Id").Limit(ContentListPageSize, ContentListPageSize*(pageindex-1)).Find(&objs)
	if err != nil {
		resInfo.Status = ReturnException
		common.LogError(fmt.Sprintf("JokeList:%v", err))
		return resInfo
	} else {
		count, _ := bb.OrmEngine.Count(&models.JokeTb{})
		resInfo.Recordcount = int(count)
		resInfo.Data = objs
		resInfo.Status = ReturnSuccess
	}
	return resInfo
}
Example #5
0
func (bb *BrowseBusiness) Heart(showid, otype int) ReturnInfo {
	resInfo := ReturnInfo{}
	sqlstr := ""
	if otype == 1 {
		sqlstr = fmt.Sprintf("update joke_tb set hearts=hearts+1 where showid=%d", showid)
	} else {
		sqlstr = fmt.Sprintf("update joke_tb set Reduce=Reduce+1 where showid=%d", showid)
	}
	_, err := bb.OrmEngine.Exec(sqlstr)
	if err != nil {
		common.LogError(fmt.Sprintf("Heart:%s,%v", sqlstr, err))
		resInfo.Status = ReturnException
		return resInfo
	} else {
		resInfo.Status = ReturnSuccess
	}
	return resInfo
}
Example #6
0
func recoverapp() {
	common.LogInfo("web end")
	if err := recover(); err != nil {
		common.LogError("web err:", err)
	}
}