func Categories() ([]entities.Category, error) {
	var err error
	var categories []entities.Category
	var categoriesKey = constants.CATEGORY_KEY
	err = utils.Get(categoriesKey, &categories)
	if err == nil {
		return categories, nil
	}
	orm := orm.NewOrm()
	_, err = orm.QueryTable("category").OrderBy("order").All(&categories, "id", "name", "order", "created_at", "updated_at")
	fmt.Print("**************err", err, "******categories", len(categories))
	return categories, err
}
Example #2
0
func User(id int) (entities.User, error) {
	var err error
	var user entities.User
	var userKey = constants.USER_KEY + string(id)
	err = utils.Get(userKey, &user)
	fmt.Println("************err:", err, "user:"******"user").Filter("id", id).One(&user, "id", "nick", "age", "cell", "mail", "sex", "CreatedAt", "UpdatedAt")
	if err == nil {
		utils.Set(userKey, user, 1000)
	}
	return user, err
}
func TestGet(t *testing.T) {
	var aa string
	utils.Get("aa", aa)
	fmt.Print("val:", aa)
}