当前位置: 首页>>代码示例>>Golang>>正文


Golang util.FormatSubListKey函数代码示例

本文整理汇总了Golang中github.com/cmu440/tribbler/util.FormatSubListKey函数的典型用法代码示例。如果您正苦于以下问题:Golang FormatSubListKey函数的具体用法?Golang FormatSubListKey怎么用?Golang FormatSubListKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FormatSubListKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RemoveSubscription

func (ts *tribServer) RemoveSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userkey := util.FormatUserKey(args.UserID)
	targetkey := util.FormatUserKey(args.TargetUserID)

	usersubs := util.FormatSubListKey(args.UserID)
	target := args.TargetUserID

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	// Make sure target exists
	if _, et := ts.ls.Get(targetkey); et != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	// Make sure user is subscribed to target
	if err := ts.ls.RemoveFromList(usersubs, target); err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		reply.Status = tribrpc.OK
	}
	return nil
}
开发者ID:pyurky,项目名称:p2,代码行数:25,代码来源:tribserver_impl.go

示例2: AddSubscription

// AddSubscription adds TargerUserID to UserID's list of subscriptions.
// Replies with status NoSuchUser if the specified UserID does not exist, and NoSuchTargerUser
// if the specified TargerUserID does not exist.
func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {

	userId := args.UserID
	targetId := args.TargetUserID

	userIdKey := util.FormatUserKey(userId)
	targetIdKey := util.FormatUserKey(targetId)

	_, ok_user := ts.libstore.Get(userIdKey)
	_, ok_target := ts.libstore.Get(targetIdKey)
	if ok_user != nil {
		reply.Status = tribrpc.NoSuchUser
	} else if ok_target != nil {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		subKey := util.FormatSubListKey(userId)

		err := ts.libstore.AppendToList(subKey, targetId)
		if err != nil {
			reply.Status = tribrpc.Exists
		} else {
			reply.Status = tribrpc.OK
		}
	}
	return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:29,代码来源:tribserver_impl.go

示例3: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userkey := util.FormatUserKey(args.UserID)
	targetkey := util.FormatUserKey(args.TargetUserID)

	usersubs := util.FormatSubListKey(args.UserID)
	target := args.TargetUserID

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	// Make sure targetUser exists
	if _, et := ts.ls.Get(targetkey); et != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	// Make sure user isn't already subscribed to target
	err := ts.ls.AppendToList(usersubs, target)
	if err == nil {
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.Exists
	}
	return nil
}
开发者ID:pyurky,项目名称:p2,代码行数:26,代码来源:tribserver_impl.go

示例4: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userid := args.UserID
	targetid := args.TargetUserID
	useridkey := util.FormatUserKey(userid)
	targetidkey := util.FormatUserKey(targetid)

	_, userExists := ts.ls.Get(useridkey)

	if userExists != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	_, targetExists := ts.ls.Get(targetidkey)

	if targetExists != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	userSubListKey := util.FormatSubListKey(userid)
	appendErr := ts.ls.AppendToList(userSubListKey, targetid)

	if appendErr != nil {
		reply.Status = tribrpc.Exists
		return nil
	}

	reply.Status = tribrpc.OK
	return nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:31,代码来源:tribserver_impl.go

示例5: GetTribblesBySubscription

/*
-format sublist
*/
func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {

	if DBG {
		fmt.Println("-----> GetTribblesBySubscription")
	}
	var usrID string = args.UserID

	//check if user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(usrID))

	if err != nil {
		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
		}
	}

	//get list of subscribers
	subscrList, err := ts.libStore.GetList(util.FormatSubListKey(usrID))

	if err != nil {
		//return err
		fmt.Println("No subscribers, or error getting list of subscribers")
		reply.Status = tribrpc.OK
		return nil
	}

	//initialise empty slice of all postKeys from subscribers
	var allPostKeys []string = make([]string, 0)

	//populate allPostKeys
	for _, currUser := range subscrList {
		currPostKeys, err := ts.libStore.GetList(util.FormatTribListKey(currUser))

		if err == nil {
			allPostKeys = append(allPostKeys, currPostKeys...)

		} else {
			//fmt.Println("0 tribs for user detected")
		}
	}

	sort.Sort(PostByTime(allPostKeys))

	//choose most recent posts, and get tribbles
	var tribList []tribrpc.Tribble = ts.getTribbleList(allPostKeys)

	reply.Tribbles = tribList
	reply.Status = tribrpc.OK
	return nil

}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:63,代码来源:tribserver_impl.go

示例6: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	subscriptions, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		return nil
	}
	reply.Tribbles = make([]tribrpc.Tribble, 0)
	mychan := make(chan []tribrpc.Tribble, 1000)
	go func() {
		for i := 0; i < len(subscriptions); i++ {
			user := subscriptions[i]
			go func() {
				tribbles, _ := ts.GetAllTribblesByUser(user)
				mychan <- tribbles
			}()
		}
	}()
	for i := 0; i < len(subscriptions); i++ {
		tribbles := <-mychan
		reply.Tribbles = append(reply.Tribbles, tribbles...)
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = prepareTribbles(reply.Tribbles)
	return nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:30,代码来源:tribserver_impl.go

示例7: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	user_id := util.FormatUserKey(args.UserID)
	target_user_id := util.FormatUserKey(args.TargetUserID)

	// If the user_id doesn't exist
	// Return error
	_, err := ts.lib_store.Get(user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	// If the target_user_id doesn't exist
	// Return error
	_, err = ts.lib_store.Get(target_user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	user_sub := util.FormatSubListKey(args.UserID)
	err = ts.lib_store.AppendToList(user_sub, args.TargetUserID)
	if err != nil {
		reply.Status = tribrpc.Exists
		return nil
	}
	reply.Status = tribrpc.OK
	return nil
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:29,代码来源:tribserver_impl.go

示例8: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	userkey := util.FormatUserKey(args.UserID)
	_, userErr := ts.libstore.Get(userkey)

	if userErr != nil {
		reply.Status = tribrpc.NoSuchUser
	} else {
		reply.Status = tribrpc.OK
		subskey := util.FormatSubListKey(args.UserID)
		subsList, _ := ts.libstore.GetList(subskey)

		totalTribList := make(Tribbles, 0)
		for i := 0; i < len(subsList); i++ {
			curUser := subsList[i]
			curtribList := ts.GetTribblesOneUser(curUser)

			for j := 0; j < len(curtribList); j++ {
				totalTribList = append(totalTribList, curtribList[j])
			}
			//totalTribList = append(totalTribList, curtribList)
		}

		sort.Sort(totalTribList)
		totalLen := len(totalTribList)
		if totalLen > 100 {
			totalLen = 100
		}
		reply.Tribbles = make(Tribbles, totalLen)
		for j := 0; j < totalLen; j++ {
			reply.Tribbles[j] = totalTribList[j]
		}
	}
	return nil

}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:35,代码来源:tribserver_impl.go

示例9: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	if args == nil {
		return errors.New("ts: Can't getSubscription nil")
	}
	if reply == nil {
		return errors.New("ts: Can't reply with nil in getSubscription")
	}

	_, err := ts.ls.Get(util.FormatUserKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = make([]tribrpc.Tribble, 0, 0)
		return nil
	}

	users, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0, 0)
		return nil
	}

	postIDs := make([]string, 0)
	for _, userID := range users {
		lst, err := ts.ls.GetList(util.FormatTribListKey(userID))
		if err == nil {
			postIDs = append(postIDs, lst...)
		}
	}

	tmp := tribbleIDs(postIDs)

	sort.Sort(tmp)
	tribbleIdsChrono := []string(tmp)

	length := 100
	if len(tribbleIdsChrono) < 100 {
		length = len(tribbleIdsChrono)
	}

	tribbles := make([]tribrpc.Tribble, length)
	var tribTmp tribrpc.Tribble
	i := 0
	for i < length {
		trib, err := ts.ls.Get(tribbleIdsChrono[i])
		if err == nil {
			json.Unmarshal([]byte(trib), &tribTmp)
			tribbles[i] = tribTmp
			i += 1 // If error occurs, we do NOT increment i
		}
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = tribbles
	return nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:55,代码来源:tribserver_impl.go

示例10: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	// Getsublist by key
	// Get tribble list by user_ids in sublist
	// sort the tribble list by the timestamp
	// retrive the first 100 tribble (Be careful about the delete operation)
	user_id := util.FormatUserKey(args.UserID)

	// If the user_id doesn't exist
	// Reture NoSuchUser
	_, err := ts.lib_store.Get(user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	// Get user's subscription_list
	user_id_list := util.FormatSubListKey(args.UserID)
	// list of IDs
	user_list, _ := ts.lib_store.GetList(user_id_list)

	if user_list == nil {
		reply.Status = tribrpc.OK
		return nil
	}

	// Get tribble_ids from the user_ids in the subscription list
	tribble_id_list := make([]string, 0)
	for _, usr_id := range user_list {
		t_id_list, err := ts.lib_store.GetList(util.FormatTribListKey(usr_id))
		if err == nil {
			tribble_id_list = append(tribble_id_list, t_id_list...)
		}
	}

	sort.Sort(SortTribbleByTimestamp(tribble_id_list))

	counter := 0
	tribble_list := make([]tribrpc.Tribble, 100)
	for _, tid := range tribble_id_list {
		tribble, err := ts.lib_store.Get(tid)
		if err == nil {
			json.Unmarshal([]byte(tribble), &tribble_list[counter])
			counter += 1
		}
		if counter >= 100 {
			break
		}
	}

	reply.Status = tribrpc.OK
	reply.Tribbles = tribble_list[:counter]
	return nil
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:53,代码来源:tribserver_impl.go

示例11: GetSubscriptions

func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	subkey := util.FormatSubListKey(args.UserID)
	userkey := util.FormatUserKey(args.UserID)
	_, userErr := ts.libstore.Get(userkey)
	if userErr != nil {
		reply.Status = tribrpc.NoSuchUser
	} else {
		list, _ := ts.libstore.GetList(subkey)
		reply.Status = tribrpc.OK
		reply.UserIDs = list
	}
	return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:13,代码来源:tribserver_impl.go

示例12: GetSubscriptions

func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	UserIDs, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err == nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = UserIDs
	} else {
		reply.Status = tribrpc.OK
		reply.UserIDs = make([]string, 0)
	}
	return nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:15,代码来源:tribserver_impl.go

示例13: GetSubscriptions

func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	key := util.FormatUserKey(args.UserID)
	if ts.checkIfKnown(key) {
		sublist_key := util.FormatSubListKey(args.UserID)
		sub_ids, err := ts.storage.GetList(sublist_key)
		if err != nil {
			sub_ids = []string{}
		}
		reply.UserIDs = sub_ids
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.NoSuchUser
	}
	return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:15,代码来源:tribserver_impl.go

示例14: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	if ts.userExist(args.TargetUserID) == false {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	err := ts.ls.AppendToList(util.FormatSubListKey(args.UserID), args.TargetUserID)
	if err == nil {
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.Exists
	}
	return nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:17,代码来源:tribserver_impl.go

示例15: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	user_key := util.FormatUserKey(args.UserID)
	target_key := util.FormatUserKey(args.TargetUserID)
	if !ts.checkIfKnown(user_key) {
		reply.Status = tribrpc.NoSuchUser
	} else if !ts.checkIfKnown(target_key) {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		sublist_key := util.FormatSubListKey(args.UserID)
		err := ts.storage.AppendToList(sublist_key, args.TargetUserID)
		if err != nil {
			reply.Status = tribrpc.Exists
		} else {
			reply.Status = tribrpc.OK
		}
	}
	return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:18,代码来源:tribserver_impl.go


注:本文中的github.com/cmu440/tribbler/util.FormatSubListKey函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。