Example #1
0
func (this *TopicController) Load() {

	var topics []*(models.Topic)
	var err error
	switch beego.AppConfig.String("database") {
	case "redis":
		topics, err = models.GetAllTopicsRedis("", "", false)
	default:
		topics, err = models.GetAllTopics("", "", false)
	}

	if err != nil {
		beego.Error(err)
	}
	this.Data["json"] = &topics
	this.ServeJson()
}
Example #2
0
func (this *HomeController) Load() {
	category := this.Input().Get("category")
	lable := this.Input().Get("lable")

	var topics []*(models.Topic)
	var err error
	switch beego.AppConfig.String("database") {
	case "redis":
		topics, err = models.GetAllTopicsRedis(category, lable, true)
	default:
		topics, err = models.GetAllTopics(category, lable, true)
	}

	if err != nil {
		beego.Error(err)
	}

	var categories []*(models.Category)
	switch beego.AppConfig.String("database") {
	case "redis":
		categories, err = models.GetAllCategoriesRedis(false)
	default:
		categories, err = models.GetAllCategories(false)
	}

	if err != nil {
		beego.Error(err)
	}

	data := &struct {
		Topics     []*models.Topic
		Categories []*models.Category
	}{
		Topics:     topics,
		Categories: categories,
	}
	this.Data["json"] = data
	this.ServeJson()
}