本文整理汇总了Golang中github.com/cmu440/tribbler/util.FormatUserKey函数的典型用法代码示例。如果您正苦于以下问题:Golang FormatUserKey函数的具体用法?Golang FormatUserKey怎么用?Golang FormatUserKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FormatUserKey函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: 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
示例5: CreateUser
func (ts *tribServer) CreateUser(args *tribrpc.CreateUserArgs, reply *tribrpc.CreateUserReply) error {
if DBG {
fmt.Println("-----> CreateUser")
}
var usrID string = args.UserID
_, err := ts.libStore.Get(util.FormatUserKey(usrID))
if err == nil {
//user not found
reply.Status = tribrpc.Exists
return nil
//return err
}
err = ts.libStore.Put(util.FormatUserKey(usrID), "exists")
if err != nil {
return nil
}
//populate reply struct
reply.Status = tribrpc.OK
return nil
}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:26,代码来源:tribserver_impl.go
示例6: 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
示例7: CreateUser
func (ts *tribServer) CreateUser(args *tribrpc.CreateUserArgs, reply *tribrpc.CreateUserReply) error {
if ts.userExist(args.UserID) == true {
reply.Status = tribrpc.Exists
return nil
}
reply.Status = tribrpc.OK
ts.ls.Put(util.FormatUserKey(args.UserID), util.FormatUserKey(args.UserID))
return nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:9,代码来源:tribserver_impl.go
示例8: DeleteTribble
func (ts *tribServer) DeleteTribble(args *tribrpc.DeleteTribbleArgs, reply *tribrpc.DeleteTribbleReply) error {
if args == nil {
return errors.New("ts: Can't delete nil")
}
if reply == nil {
return errors.New("ts: Can't reply with nil in Delete")
}
_, err := ts.ls.Get(util.FormatUserKey(args.UserID))
if err != nil {
reply.Status = tribrpc.NoSuchUser
return nil
}
err = ts.ls.RemoveFromList(util.FormatTribListKey(args.UserID), args.PostKey)
if err != nil {
reply.Status = tribrpc.NoSuchPost
return nil
}
if ts.ls.Delete(args.PostKey) != nil {
reply.Status = tribrpc.NoSuchPost
return errors.New("Fatal, failed to delete a key")
}
reply.Status = tribrpc.OK
return nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:27,代码来源:tribserver_impl.go
示例9: DeleteTribble
func (ts *tribServer) DeleteTribble(args *tribrpc.DeleteTribbleArgs, reply *tribrpc.DeleteTribbleReply) error {
userkey := util.FormatUserKey(args.UserID)
_, userErr := ts.libstore.Get(userkey)
if userErr != nil {
reply.Status = tribrpc.NoSuchUser
} else {
delErr := ts.libstore.Delete(args.PostKey)
if delErr != nil {
reply.Status = tribrpc.NoSuchPost
return nil
}
tribkey := util.FormatTribListKey(args.UserID)
delListErr := ts.libstore.RemoveFromList(tribkey, args.PostKey)
if delListErr != nil {
reply.Status = tribrpc.NoSuchPost
return nil
}
reply.Status = tribrpc.OK
}
return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:25,代码来源:tribserver_impl.go
示例10: GetTribbles
func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
key := util.FormatUserKey(args.UserID)
if ts.checkIfKnown(key) {
triblist_key := util.FormatTribListKey(args.UserID)
post_ids, err := ts.storage.GetList(triblist_key)
if err != nil {
post_ids = []string{}
}
sort.Sort(ByChrono(post_ids))
bound := min(100, len(post_ids))
tribs := make([]tribrpc.Tribble, bound)
for i, v := range post_ids[0:bound] {
postStr, err := ts.storage.Get(v)
if err != nil {
return err
}
trib := tribrpc.Tribble{}
json.Unmarshal([]byte(postStr), &trib)
tribs[i] = trib
}
reply.Tribbles = tribs
reply.Status = tribrpc.OK
} else {
reply.Status = tribrpc.NoSuchUser
}
return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:27,代码来源:tribserver_impl.go
示例11: PostTribble
func (ts *tribServer) PostTribble(args *tribrpc.PostTribbleArgs, reply *tribrpc.PostTribbleReply) error {
key := util.FormatUserKey(args.UserID)
if ts.checkIfKnown(key) {
newTrib := tribrpc.Tribble{args.UserID, time.Now(), args.Contents}
tribStr, err := json.Marshal(newTrib)
if err != nil {
return err
}
id := newTrib.UserID
time := newTrib.Posted.UnixNano()
post_key := util.FormatPostKey(id, time)
for ts.checkIfKnown(post_key) {
post_key = util.FormatPostKey(id, time)
}
err = ts.storage.Put(post_key, string(tribStr))
if err != nil {
return err
}
triblist_key := util.FormatTribListKey(args.UserID)
err = ts.storage.AppendToList(triblist_key, post_key)
if err != nil {
return err
}
reply.PostKey = post_key
reply.Status = tribrpc.OK
} else {
reply.Status = tribrpc.NoSuchUser
}
return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:33,代码来源:tribserver_impl.go
示例12: DeleteTribble
func (ts *tribServer) DeleteTribble(args *tribrpc.DeleteTribbleArgs, reply *tribrpc.DeleteTribbleReply) error {
key := util.FormatUserKey(args.UserID)
post_key := args.PostKey
if !ts.checkIfKnown(key) {
reply.Status = tribrpc.NoSuchUser
} else if !ts.checkIfKnown(post_key) {
reply.Status = tribrpc.NoSuchPost
} else {
err := ts.storage.Delete(post_key)
if err != nil {
return err
}
triblist_key := util.FormatTribListKey(args.UserID)
err = ts.storage.RemoveFromList(triblist_key, post_key)
if err != nil {
return err
}
reply.Status = tribrpc.OK
}
return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:25,代码来源:tribserver_impl.go
示例13: 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
示例14: 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
示例15: PostTribble
func (ts *tribServer) PostTribble(args *tribrpc.PostTribbleArgs, reply *tribrpc.PostTribbleReply) error {
userkey := util.FormatUserKey(args.UserID)
_, userErr := ts.libstore.Get(userkey)
if userErr != nil {
reply.Status = tribrpc.NoSuchUser
} else {
postTime := time.Now()
tribble := &tribrpc.Tribble{
UserID: args.UserID,
Posted: postTime,
Contents: args.Contents,
}
marshalTribble, _ := json.Marshal(tribble)
unixTime := int64(postTime.UnixNano())
postKey := util.FormatPostKey(args.UserID, unixTime)
putErr := ts.libstore.Put(postKey, string(marshalTribble))
if putErr != nil {
return errors.New("Fail to put postkey and tribble")
}
tribListKey := util.FormatTribListKey(args.UserID)
appendErr := ts.libstore.AppendToList(tribListKey, postKey)
if appendErr != nil {
return errors.New("Fail to append tribble to user")
}
reply.Status = tribrpc.OK
reply.PostKey = postKey
}
return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:35,代码来源:tribserver_impl.go
示例16: userExist
func (ts *tribServer) userExist(UserID string) bool {
_, err := ts.ls.Get(util.FormatUserKey(UserID))
if err != nil {
return false
}
return true
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:7,代码来源:tribserver_impl.go
示例17: DeleteTribble
func (ts *tribServer) DeleteTribble(args *tribrpc.DeleteTribbleArgs, reply *tribrpc.DeleteTribbleReply) error {
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
}
user_trib_list_key := util.FormatTribListKey(args.UserID)
err = ts.lib_store.RemoveFromList(user_trib_list_key, args.PostKey)
if err != nil {
reply.Status = tribrpc.NoSuchPost
fmt.Println(2)
return nil
}
err = ts.lib_store.Delete(args.PostKey)
if err != nil {
reply.Status = tribrpc.NoSuchPost
return nil
}
reply.Status = tribrpc.OK
return nil
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:28,代码来源:tribserver_impl.go
示例18: 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
示例19: 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
示例20: 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
注:本文中的github.com/cmu440/tribbler/util.FormatUserKey函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论