示例#1
0
func DeleteUserInfoByUid(uid uint64) error {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
	if err := c.Remove(bson.M{"uid": uid}); err != nil {
		return errors.As(err, uid)
	}
	return nil
}
示例#2
0
func (msg *UserMsgItem) SafeMapTimeoutCall(key interface{}) {
	// 超时未删除则保存到db
	c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE)
	if err := c.Insert(msg); err != nil {
		syslog.Info(err, *msg)
	}
}
示例#3
0
func SaveUserMsgToDB(userMsg *UserMsgItem) {
	// 超时未删除则保存到db
	c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE)
	if err := c.Insert(userMsg); err != nil {
		syslog.Info(err, *userMsg)
	}
}
示例#4
0
func SetUserInfo(sel, set map[string]interface{}) error {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
	if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil {
		return errors.As(err, sel, set)
	}
	return nil
}
示例#5
0
func SetTeamMember(sel, set map[string]interface{}) error {
	c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)

	if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil {
		return errors.As(err, sel, set)
	}
	return nil
}
示例#6
0
func deleteFile(filelist []string) error {
	c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE)
	_, err := c.RemoveAll(bson.M{"filename": bson.M{"$in": filelist}})
	if err != nil && err != mgo.ErrNotFound {
		return errors.As(err, filelist)
	}
	return nil
}
示例#7
0
func GetUserCount() (uint64, error) {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
	count, err := c.Find(nil).Count()
	if err != nil {
		return 0, errors.As(err)
	}
	return uint64(count), nil
}
示例#8
0
func GetTeamList(sel map[string]interface{}, start, count int) ([]TeamInfo, error) {
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)

	team_list := []TeamInfo{}
	err := c.Find(bson.M(sel)).Skip(start).Limit(count).All(&team_list)

	return team_list, errors.As(err, sel)
}
示例#9
0
func DeleteTeam(teamid uint64) error {
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)

	err := c.Remove(bson.M{"teamid": teamid})
	if err != mgo.ErrNotFound {
		return errors.As(err, teamid)
	}
	return nil
}
示例#10
0
func UserMsgInit() error {
	c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE)

	index := mgo.Index{
		Key: []string{"touid", "msgid"},
	}

	return errors.As(c.EnsureIndex(index))
}
示例#11
0
func DeleteTeamMember(teamid, uid uint64) error {
	c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)

	err := c.Remove(bson.M{"teamid": teamid, "uid": uid})
	if err != mgo.ErrNotFound {
		return errors.As(err, uid, teamid)
	}
	return nil
}
示例#12
0
func DeleteFriend(uid, fid uint64) error {
	c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE)

	err := c.Remove(bson.M{"fuid": fid, "uid": uid})
	if err != mgo.ErrNotFound {
		return errors.As(err, fid)
	}
	return nil
}
示例#13
0
func GetUserInfo(sel map[string]interface{}) (*UserInfo, error) {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)

	user := &UserInfo{}
	if err := c.Find(bson.M(sel)).One(user); err != nil {
		return nil, errors.As(err, sel)
	}
	return user, nil
}
示例#14
0
func addFile(file *File) error {
	c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE)
	sel := bson.M{"filename": file.Filename}
	set := bson.M{
		"$set":         bson.M{"expiredtime": file.ExpiredTime},
		"$setOnInsert": bson.M{"createtime": file.CreateTime},
	}
	_, err := c.Upsert(sel, set)
	return errors.As(err, *file)
}
示例#15
0
func FriendInit() error {
	c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE)

	index := mgo.Index{
		Key:      []string{"uid", "fuid"},
		Unique:   true,
		DropDups: true,
	}

	return errors.As(c.EnsureIndex(index))
}
示例#16
0
func TeamMemberInit() error {
	c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)

	index := mgo.Index{
		Key:      []string{"teamid", "uid"},
		Unique:   true,
		DropDups: true,
	}

	return errors.As(c.EnsureIndex(index))
}
示例#17
0
func AddFriend(friend *Friend) error {
	//sel := map[string]interface{}{"uid":friend.Uid, "fuid":friend.FUid}
	//set := map[string]interface{}{"type":friend.Type}
	if err := DeleteFriend(friend.Uid, friend.FUid); err != nil {
		return errors.As(err, *friend)
	}
	c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE)

	friend.CreateDT = time.Now().Format(protocol.DATETIME_FMT)
	friend.UpdateDT = time.Now().Format(protocol.DATETIME_FMT)
	return errors.As(c.Insert(friend), *friend)
}
示例#18
0
func GetNextUserId() (uint64, error) {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)

	userInfo := &UserInfo{}
	if err := c.Find(nil).Sort("-uid").One(&userInfo); err != nil {
		if err == mgo.ErrNotFound {
			return uint64(MIN_USER_ID), nil
		}
		return 0, errors.As(err)
	}
	return userInfo.Uid + 1, nil
}
示例#19
0
func GetTeam(teamid uint64) *TeamInfo {
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)

	team := &TeamInfo{}

	iter := c.Find(bson.M{"teamid": teamid}).Iter()
	defer iter.Close()

	if iter.Next(team) {
		return team
	}
	return nil
}
示例#20
0
func GetTeamMember(teamid, uid uint64) *TeamMember {
	c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)

	tm := &TeamMember{}
	iter := c.Find(bson.M{"teamid": teamid, "uid": uid}).Iter()
	defer iter.Close()

	if iter.Next(tm) {
		return tm
	}

	return nil
}
示例#21
0
func GetFriendList(uid uint64, typ int) ([]uint64, error) {
	c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE)

	friend := &Friend{}
	uids := []uint64{}
	iter := c.Find(bson.M{"uid": uid, "type": typ}).Iter()
	defer iter.Close()

	for iter.Next(friend) {
		uids = append(uids, friend.FUid)
	}
	return uids, nil
}
示例#22
0
func GetFriend(uid, fid uint64) *Friend {
	c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE)

	friend := &Friend{}

	iter := c.Find(bson.M{"fuid": fid, "uid": uid}).Iter()
	defer iter.Close()

	if iter.Next(friend) {
		return friend
	}
	return nil
}
示例#23
0
func GetSysTeamList() ([]TeamInfo, error) {
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)
	teamList := []TeamInfo{}
	team := &TeamInfo{}

	iter := c.Find(bson.M{"teamtype": 1}).Iter()
	defer iter.Close()

	for iter.Next(team) {
		teamList = append(teamList, *team)
	}
	return teamList, nil

}
示例#24
0
func (this *FileMgr) RemoveExpiredFile() error {
	c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE)

	expiredTime := time.Now().Unix()
	iter := c.Find(bson.M{"expiredtime": bson.M{"$lt": expiredTime}}).Iter()
	defer iter.Close()
	file := &File{}
	keys := []string{}
	for iter.Next(file) {
		keys = append(keys, file.Filename)
	}
	QiniuDeleteFiles(keys)
	return nil
}
示例#25
0
func UserInfoInit() error {
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)

	index := mgo.Index{
		Key:        []string{"uid"},
		Unique:     true,
		DropDups:   true,
		Background: true,
	}
	if err := c.EnsureIndex(index); err != nil {
		return errors.As(err, index)
	}
	return nil
}
示例#26
0
func GetTeamMemberList(teamid uint64) ([]uint64, error) {
	c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)

	tm := &TeamMember{}
	uids := []uint64{}

	iter := c.Find(bson.M{"teamid": teamid}).Iter()
	defer iter.Close()

	for iter.Next(tm) {
		uids = append(uids, tm.Uid)
	}

	return uids, nil
}
示例#27
0
func CreateTeam(team *TeamInfo) error {
	team_mutex_lock.Lock()
	defer team_mutex_lock.Unlock()

	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)
	if team.TeamId == 0 {
		teamId, err := GetNextTeamId(team.Uid)
		if err != nil {
			return errors.As(err, *team)
		}
		team.TeamId = teamId
	}

	team.CreateDate = time.Now().Format(DATETIME_FMT)
	return errors.As(c.Insert(team), *team)
}
示例#28
0
//User System
func SaveUserInfo(user *UserInfo) error {
	user_mutex_lock.Lock()
	defer user_mutex_lock.Unlock()
	c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
	if user.Uid == 0 {
		uid, err := GetNextUserId()
		if err != nil {
			return errors.As(err, *user)
		}
		user.Uid = uid
	}

	if err := c.Insert(user); err != nil {
		return errors.As(err, *user)
	}

	return nil
}
示例#29
0
func DelUserMsg(uid, msgid uint64) error {
	// 在缓存就不操作数据库
	fmt.Println()
	key := msgKey(uid, msgid)
	if msg := g_userMsgMgr.msgMap.Get(key); msg != nil {
		g_userMsgMgr.msgMap.Delete(key)
		return nil
	}
	// 不在缓存就删除数据库
	g_userMsgMgr.msgMap.Delete(msgKey(uid, msgid))

	c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE)

	err := c.Remove(bson.M{"msgid": msgid, "touid": uid})
	if err != mgo.ErrNotFound {
		return errors.As(err, uid, msgid)
	}
	return nil
}
示例#30
0
func QiniuInit() error {
	c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE)

	index := mgo.Index{
		Key:      []string{"filename"},
		Unique:   true,
		DropDups: true,
	}

	g_file_mgr = &FileMgr{
		fileCh:       make(chan *File, 100),
		expiredTimer: time.Tick(time.Hour),
		waitGroup:    sync.NewWaitGroup(),
		rsClient:     rs.New(&digest.Mac{AccessKey: g_access_key, SecretKey: []byte(g_secret_key)}),
	}

	go g_file_mgr.run()

	return errors.As(c.EnsureIndex(index))
}