func (this *CategoryController) Load() { var categories []*(models.Category) var err error switch beego.AppConfig.String("database") { case "redis": categories, err = models.GetAllCategoriesRedis(true) default: categories, err = models.GetAllCategories(true) } if err != nil { beego.Error(err) } this.Data["json"] = &categories this.ServeJson() }
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() }