當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.As函數代碼示例

本文整理匯總了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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:32,代碼來源:msg_server.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:28,代碼來源:friend.go

示例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)
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:12,代碼來源:friend.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:14,代碼來源:team.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:25,代碼來源:friend.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:7,代碼來源:user.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:7,代碼來源:user.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:28,代碼來源:client.go

示例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)
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:16,代碼來源:team.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:member.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:user.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:qiniu.go

示例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)
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:team.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:user.go

示例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
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:8,代碼來源:user.go


注:本文中的project/common/errors.As函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。