本文整理汇总了Golang中github.com/cmu440/tribbler/rpc/tribrpc.SubscriptionReply类的典型用法代码示例。如果您正苦于以下问题:Golang SubscriptionReply类的具体用法?Golang SubscriptionReply怎么用?Golang SubscriptionReply使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubscriptionReply类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: AddSubscription
func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
UserKey := GenerateUserKey(args.UserID)
TargetUserKey := GenerateUserKey(args.TargetUserID)
_, err := ts.lib.Get(UserKey)
if err != nil {
reply.Status = tribrpc.NoSuchUser
return nil
}
_, err = ts.lib.Get(TargetUserKey)
if err != nil {
reply.Status = tribrpc.NoSuchTargetUser
return nil
}
SubsKey := GenerateSubsKey(args.UserID)
err = ts.lib.AppendToList(SubsKey, args.TargetUserID)
if err != nil {
reply.Status = tribrpc.Exists
return nil
}
reply.Status = tribrpc.OK
return nil
}
示例3: AddSubscription
func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
LOGE.Printf("AddSubscription:: args=%s\n", string(marshal(*args)))
userIDKey := GetUserKey(args.UserID)
targetUserIDKey := GetUserKey(args.TargetUserID)
_, err := ts.lib.Get(userIDKey)
if err != nil {
reply.Status = tribrpc.NoSuchUser
return nil
}
_, err = ts.lib.Get(targetUserIDKey)
if err != nil {
reply.Status = tribrpc.NoSuchTargetUser
return nil
}
userSubsKey := GetsSubsKey(args.UserID)
err = ts.lib.AppendToList(userSubsKey, args.TargetUserID)
if err != nil {
reply.Status = tribrpc.Exists
return nil
}
reply.Status = tribrpc.OK
LOGE.Printf("AddSubscription:: reply=%s\n", string(marshal(reply)))
return nil
}
示例4: 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
}
示例5: 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
}
示例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
}
示例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
}
示例8: 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
}
示例9: 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
}
示例10: doSub
func (ts *tribServer) doSub(user, target string, reply *tribrpc.SubscriptionReply, mode uint8) error {
_, err := ts.Libstore.Get(user)
switch err {
case nil: // expected case, do nothing
case libstore.ErrorKeyNotFound:
reply.Status = tribrpc.NoSuchUser
return nil
default:
return err
}
_, err = ts.Libstore.Get(target)
switch err {
case nil: // expected case, do nothing
case libstore.ErrorKeyNotFound:
reply.Status = tribrpc.NoSuchTargetUser
return nil
default:
return err
}
subscListKey := makeSubscListKey(user)
subscribes, err := ts.Libstore.GetList(subscListKey)
switch err {
case nil:
// we have successfully retrieved the list of subscribes
switch mode {
case doSubAppend:
// check duplicate subscribes
for _, subscribe := range subscribes {
if subscribe == target {
reply.Status = tribrpc.Exists
return nil
}
}
case doSubRemove:
// check whether exist
existTarget := false
for _, subscribe := range subscribes {
if subscribe == target {
existTarget = true
break
}
}
if !existTarget {
reply.Status = tribrpc.NoSuchTargetUser
return nil
}
default:
panic("")
}
case libstore.ErrorKeyNotFound:
// This user hasn't done subscribe before. do thing
default:
return err
}
switch mode {
case doSubAppend:
err = ts.Libstore.AppendToList(subscListKey, target)
case doSubRemove:
err = ts.Libstore.RemoveFromList(subscListKey, target)
}
if err == nil { // ignore errors
}
reply.Status = tribrpc.OK
return nil
}
示例11: AddSubscription
func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
if DBG {
fmt.Println("-----> AddSubscription")
}
/*
-Check if user present
-Check if user being subscribed to is present
-append to list: sublist key formatter,
*/
var thisUsrId string = args.UserID
var subscrId string = args.TargetUserID
//check if this user present in server
_, err := ts.libStore.Get(util.FormatUserKey(thisUsrId))
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")
return nil
}
}
//check if subscribe user is present
_, err = ts.libStore.Get(util.FormatUserKey(subscrId))
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.NoSuchTargetUser
return nil
default:
fmt.Println("ERROR in tribserver: wrong error message received")
}
}
//add to list of subscribers
err = ts.libStore.AppendToList(util.FormatSubListKey(thisUsrId), subscrId)
if err != nil {
//TODO after checkpoint, case on err
reply.Status = tribrpc.Exists
return nil
}
/* no error */
reply.Status = tribrpc.OK
return nil
}
示例12: RemoveSubscription
/*
check if both values exist, then delete the sub
*/
func (ts *tribServer) RemoveSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
if DBG {
fmt.Println("-----> RemoveSubscription")
}
var thisUsrId string = args.UserID
var subscrId string = args.TargetUserID
//check if this user present in server
_, err := ts.libStore.Get(util.FormatUserKey(thisUsrId))
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")
}
}
//check if subscribe user is present
_, err = ts.libStore.Get(util.FormatUserKey(subscrId))
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.NoSuchTargetUser
return nil
default:
fmt.Println("ERROR in tribserver: wrong error message received")
return nil
}
}
//retrieve list of subsriber user IDs
err = ts.libStore.RemoveFromList(util.FormatSubListKey(thisUsrId), subscrId)
if err == nil {
reply.Status = tribrpc.OK
return nil
}
switch err.Error() {
case ITEM_NOT_FOUND:
//User present, no subscriptions
reply.Status = tribrpc.NoSuchTargetUser
//Empty list of user IDs
return nil
case WRONG_SERVER:
fmt.Println("ERROR: WRONG SERVER in tribserver")
return errors.New("Wrong server contacted!")
case KEY_NOT_FOUND:
fmt.Println("TribServ: Key was not found!")
reply.Status = tribrpc.NoSuchTargetUser
return nil
default:
fmt.Println("ERROR in tribserver: wrong error message received")
}
if err != nil {
//TODO after checkpoint, case on err
reply.Status = tribrpc.NoSuchTargetUser
return nil
}
return nil
}