示例#1
0
文件: user.go 项目: yonglehou/ohlala
func User_GetByTicket(ticket string) (*User, error) {
	redisClient := GetRedis()
	defer redisClient.Quit()

	id, err := redisClient.Get(ticket)
	if err != nil {
		return nil, err
	}

	if id.String() == "" {
		return nil, nil
	}

	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	var user *User = new(User)
	err = db.GetStruct(user, "id=?", id.String())
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return nil, err
	}
	if user.Id > 0 {
		return user, nil
	}
	return nil, nil
}
示例#2
0
文件: todo.go 项目: jango2015/goku
func GetTodo(id int) (Todo, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	var todo Todo = Todo{}
	err := db.GetStruct(&todo, "id=?", id)
	return todo, err
}
示例#3
0
文件: topic.go 项目: yonglehou/ohlala
// 保持topic到数据库,同时建立topic与link的关系表
// 如果topic已经存在,则直接建立与link的关联
// 全部成功则返回true
func Topic_SaveTopics(topics string, linkId int64) bool {
	if topics == "" {
		return true
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	success := true
	topicList := strings.Split(topics, ",")
	for _, topic := range topicList {
		topicLower := strings.ToLower(topic)
		t := new(Topic)
		err := db.GetStruct(t, "`name_lower`=?", topic)
		if err != nil {
			goku.Logger().Logln(topic)
			goku.Logger().Errorln(err.Error())
			success = false
			continue
		}
		if t.Id < 1 {
			t.Name = topic
			t.NameLower = topicLower
			_, err = db.InsertStruct(t)
			if err != nil {
				goku.Logger().Errorln(err.Error())
				success = false
				continue
			}
		}
		if t.Id > 0 && linkId > 0 {
			_, err = db.Insert("topic_link", map[string]interface{}{"topic_id": t.Id, "link_id": linkId})
			if err != nil {
				goku.Logger().Errorln(err.Error())
				success = false
			} else {
				// 成功,更新话题的链接数量统计
				Topic_IncCount(db, t.Id, "link_count", 1)

				redisClient := GetRedis()
				defer redisClient.Quit()
				// 加入推送队列
				// 格式: pushtype,topicid,linkid,timestamp
				qv := fmt.Sprintf("%v,%v,%v,%v", LinkForUser_ByTopic, t.Id, linkId, time.Now().Unix())
				_, err = redisClient.Lpush(golink.KEY_LIST_PUSH_TO_USER, qv)
				if err != nil {
					goku.Logger().Errorln(err.Error())
				}
			}
		}
	}
	return success
}
示例#4
0
文件: user.go 项目: t7er/ohlala
func User_GetById(id int64) *User {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	u := new(User)
	err := db.GetStruct(u, "id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	if u.Id > 0 {
		return u
	}
	return nil
}
示例#5
0
文件: topic.go 项目: yonglehou/ohlala
func Topic_GetById(id int64) (*Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	t := new(Topic)
	err := db.GetStruct(t, "`id`=?", id)
	if err != nil || t.Id == 0 {
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		t = nil
	}
	return t, err
}
示例#6
0
文件: topic.go 项目: yonglehou/ohlala
func Topic_GetByName(name string) (*Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	t := new(Topic)
	err := db.GetStruct(t, "`name`=?", strings.ToLower(name))
	if err != nil || t.Id == 0 {
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		t = nil
	}
	return t, err
}
示例#7
0
func Comment_GetById(id int64) (*Comment, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	c := new(Comment)
	err := db.GetStruct(c, "id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	if c.Id > 0 {
		return c, nil
	}
	return nil, nil
}
示例#8
0
文件: link.go 项目: yonglehou/ohlala
func Link_GetById(id int64) (*Link, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	l := new(Link)
	err := db.GetStruct(l, "id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	if l.Id > 0 {
		return l, nil
	}
	return nil, nil
}
示例#9
0
文件: user.go 项目: t7er/ohlala
func User_GetByName(name string) (*User, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	u := new(User)
	err := db.GetStruct(u, "name_lower=?", strings.ToLower(name))
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	if u.Id > 0 {
		return u, nil
	}
	return nil, nil
}
示例#10
0
文件: link.go 项目: yonglehou/ohlala
// url不区分大小写
func Link_GetByUrl(url string) (*Link, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	l := new(Link)
	urlMd5 := utils.MD5_16(strings.ToLower(url))
	err := db.GetStruct(l, "context_md5=? and `status`<>2 order by comment_count desc", urlMd5)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	if l.Id > 0 {
		return l, nil
	}
	return nil, nil
}
示例#11
0
//验证邀请码
func VerifyInviteKey(key string) *RegisterInvite {
	if !golink.Invite_Enabled {
		return new(RegisterInvite)
	}
	if len(key) != golink.Genetic_Key_Len {
		return nil
	}

	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	ri := new(RegisterInvite)
	err := db.GetStruct(ri, "`Guid`=? AND `expired_date`>=? AND `is_register`=0", key, time.Now())
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}

	if len(ri.Guid) > 0 {
		return ri
	}
	return nil
}