本文整理汇总了Golang中project/common/errors.As函数的典型用法代码示例。如果您正苦于以下问题:Golang As函数的具体用法?Golang As怎么用?Golang As使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了As函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SendMsg
func (h *Handler) SendMsg(head *common.PackageHead, jsonBody []byte, tail *common.PackageTail) ([]byte, error) {
var req SendUserMsg
if err := json.Unmarshal(jsonBody, &req); err != nil {
return nil, errors.As(err, string(jsonBody))
}
var msg message.UserMsgItem
msg.SendTime = uint32(time.Now().Unix())
msg.MsgId = message.GetUserMsgID()
msg.FromUid = tail.UID
msg.ToUid = req.ToUid
msg.Content = req.Content
msg.Type = req.Type
msg.ExtraData = req.ExtraData
msgBody, err := json.Marshal(msg)
if err != nil {
return nil, errors.As(err, msg)
}
msgBuf := common.GetBuffer()
defer common.PutBuffer(msgBuf)
head.PkgLen = uint16(common.DATA_PACKAGE_HEAD_SIZE + len(jsonBody))
if err := common.Package(msgBuf, head, msgBody, tail); err != nil {
return nil, errors.As(err)
}
common.NsqPublish(common.MSG_CENTER_TOPIC, msgBuf.Bytes())
message.SaveUserMsg(&msg)
respStr := fmt.Sprintf(`{"msgid":%d,"sendtime":%d}`, msg.MsgId, msg.SendTime)
return []byte(respStr), nil
}
示例2: RedisAddFriend
func RedisAddFriend(uid, fid uint64, typ int) error {
userKey := ""
if err := RedisDeleteFriend(uid, fid, typ); err != nil {
return errors.As(err, uid, fid, typ)
}
if typ == 1 {
userKey = fmt.Sprintf("%s%d", SET_WHITELIST, uid)
} else {
userKey = fmt.Sprintf("%s%d", SET_BLACKLIST, uid)
// 加入黑名单 删除白名单
if err := RedisDeleteFriend(uid, fid, 1); err != nil {
return errors.As(err, uid, fid, typ)
}
}
val := fmt.Sprintf("%d", fid)
g_redis_client.SAdd(userKey, val)
// 双向好友
if typ == 1 {
key_2 := fmt.Sprintf("%s%d", SET_WHITELIST, fid)
uid_2 := fmt.Sprintf("%d", uid)
g_redis_client.SAdd(key_2, uid_2)
}
return nil
}
示例3: AddFriend
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)
}
示例4: RedisQueryTeam
func RedisQueryTeam(tid uint64) (*TeamInfo, error) {
userKey := fmt.Sprintf("%s%d", KEY_TEAM_INFO, tid)
val, err := redis.RedisGet(userKey)
if err != nil {
return nil, errors.As(err, tid)
}
team := &TeamInfo{}
if err := json.Unmarshal([]byte(val), team); err != nil {
return nil, errors.As(err, string(val))
}
return team, nil
}
示例5: RedisQueryFriendList
func RedisQueryFriendList(uid uint64, typ int) ([]uint64, error) {
userKey := ""
if typ == 1 {
userKey = fmt.Sprintf("%s%d", SET_WHITELIST, uid)
} else {
userKey = fmt.Sprintf("%s%d", SET_BLACKLIST, uid)
}
strUidList, err := g_redis_client.SMembers(userKey).Result()
if err != nil {
return []uint64{}, errors.As(err, uid, typ)
}
if strUidList == nil || len(strUidList) < 1 {
return []uint64{}, nil
}
uidList := make([]uint64, len(strUidList))
for i, val := range strUidList {
uidList[i], _ = strconv.ParseUint(val, 10, 64)
}
return uidList, nil
}
示例6: DeleteUserInfoByUid
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
}
示例7: SetUserInfo
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
}
示例8: Response
func (c *Client) Response(msg *protocol.DataPackage) error {
head := msg.Head
tail := msg.Tail
if (head.Command == protocol.CLIENT_CMD_USER_LOGIN || head.Command == protocol.CLIENT_CMD_USER_REGISTER) && tail.UID != 0 {
c.Uid = tail.UID
c.Stat = CLIENT_STATE_ONLINE
}
buf := protocol.GetBuffer()
defer protocol.PutBuffer(buf)
binary.Write(buf, binary.BigEndian, head)
binary.Write(buf, binary.BigEndian, msg.BodyData())
// write to Conn
c.Conn.SetDeadline(time.Now().Add(NET_WRITE_DATELINE))
if _, err := c.Conn.Write(buf.Bytes()); err != nil {
if e, ok := err.(net.Error); ok && e.Timeout() {
syslog.Info("write timeouat:", err, *c)
return nil
}
syslog.Warn("write to conn fail :", err.Error(), msg.Tail)
return errors.As(err)
} else {
syslog.Debug2("write to conn success:", head, string(msg.BodyData()), msg.Tail)
}
return nil
}
示例9: CreateTeam
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)
}
示例10: SetTeamMember
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
}
示例11: GetUserCount
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
}
示例12: deleteFile
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
}
示例13: GetTeamList
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)
}
示例14: ModifyUserPwdByUid
func ModifyUserPwdByUid(uid uint64, pwd string) error {
sel := map[string]interface{}{"uid": uid}
set := map[string]interface{}{"password": pwd}
if err := SetUserInfo(sel, set); err != nil {
return errors.As(err, uid, pwd)
}
return nil
}
示例15: ModifyUserPwdByPhoneNum
func ModifyUserPwdByPhoneNum(phonenum, pwd string) error {
sel := map[string]interface{}{"phonenum": phonenum}
set := map[string]interface{}{"password": pwd}
if err := SetUserInfo(sel, set); err != nil {
return errors.As(err, phonenum, pwd)
}
return nil
}