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


Golang errors.As函数代码示例

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


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

示例1: GetUserTeamMsgList

func GetUserTeamMsgList(uid uint64) ([]*TextTeamMsg, error) {
	msgList := []*TextTeamMsg{}
	msgIdList, err := RedisGetUserTeamMsgList(uid)
	if err != nil {
		return msgList, errors.As(err, uid)
	}
	for _, msgId := range msgIdList {
		msgBuf, err := RedisGetTeamMsg(msgId)
		if err != nil {
			return msgList, errors.As(err, msgId)
		}
		_, jsonBody, _, err := common.UnpackageData(msgBuf)
		if err != nil {
			return msgList, errors.As(err, uid)
		}
		msg := new(TextTeamMsg)
		if err := json.Unmarshal(jsonBody, msg); err != nil {
			return msgList, errors.As(err, string(jsonBody))
		}

		msg.CmdType = common.DU_PUSH_CMD_IM_TEAM_MSG
		msgList = append(msgList, msg)
	}

	return msgList, nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:26,代码来源:team.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)
	redis.RedisSAdd(userKey, val)

	// 双向好友
	if typ == 1 {
		key_2 := fmt.Sprintf("%s%d", SET_WHITELIST, fid)
		uid_2 := fmt.Sprintf("%d", uid)
		redis.RedisSAdd(key_2, uid_2)
	}

	return nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:28,代码来源:friend.go

示例3: ConsumerGO

func ConsumerGO(topic, channel string, goCount uint, handle Handler) (*ConsumerT, error) {
	msgHandle := &ConsumerT{
		consumers: []*nsq.Consumer{},
		handle:    handle,
		msgCh:     make(chan *Message, MSG_CHAN_SIZE),
		waitGroup: sync_.NewWaitGroup(),
	}
	addrSlice := strings.Split(g_nsqdMgr.addrs, ",")
	for _, addr := range addrSlice {
		for i := 0; i < CONSUMER_COUNT_PER_ADDR; i++ {
			consumer, err := nsq.NewConsumer(topic, channel, nsq.NewConfig())
			if err != nil {
				return nil, errors.As(err, topic, channel)
			}
			consumer.SetLogger(nil, nsq.LogLevelInfo)
			consumer.AddHandler(msgHandle)
			if err := consumer.ConnectToNSQD(addr); err != nil {
				return nil, errors.As(err, topic, channel, g_nsqdMgr.addrs)
			}
			msgHandle.consumers = append(msgHandle.consumers, consumer)
		}
	}
	g_nsqdMgr.consumers = msgHandle
	for i := 0; i < int(goCount); i++ {
		go msgHandle.work()
	}
	return msgHandle, nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:28,代码来源:nsq.go

示例4: NewLocation

func (location *LocationInfo) NewLocation() error {
	session := common.MongoGet()
	defer common.MongoPut(session)

	c := session.DB("du").C("location")

	index := mgo.Index{
		Key:        []string{"$2d:loc"},
		Bits:       26,
		Background: true,
	}
	if err := c.EnsureIndex(index); err != nil {
		return errors.As(err, index)
	}

	newLoc := bson.M{
		"uid":      location.Uid,
		"loc":      location.Loc,
		"sendtime": location.SendTime,
	}

	if err := c.Insert(newLoc); err != nil {
		return errors.As(err, newLoc)
	}

	return nil
}
开发者ID:sunyuantao,项目名称:windows,代码行数:27,代码来源:location.go

示例5: init

func init() {
	if err := TeamMemberInit(); err != nil {
		panic(errors.As(err).Error())
	}

	if err := TeamInfoInit(); err != nil {
		panic(errors.As(err).Error())
	}
}
开发者ID:sunyuantao,项目名称:windows,代码行数:9,代码来源:init.go

示例6: init

func init() {
	if err := FriendInit(); err != nil {
		panic(errors.As(err).Error())
	}

	if err := UserInfoInit(); err != nil {
		panic(errors.As(err).Error())
	}
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:9,代码来源:init.go

示例7: SetUserState

func SetUserState(us *UserState) error {
	key := fmt.Sprintf("user_state_%v", us.Uid)
	body, err := json.Marshal(us)
	if err != nil {
		return errors.As(err, *us)
	}
	if err := redis_.Set(key, string(body)); err != nil {
		return errors.As(err, string(body))
	}
	return nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:11,代码来源:state.go

示例8: SetUserStateOnline

func SetUserStateOnline(uid uint64, online bool) error {
	us, err := GetUserState(uid)
	if err != nil {
		return errors.As(err, uid, online)
	}
	us.Online = online
	if err := SetUserState(us); err != nil {
		return errors.As(err, uid, online)
	}
	return nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:11,代码来源:state.go

示例9: 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(common.DATETIME_FMT)
	friend.UpdateDT = time.Now().Format(common.DATETIME_FMT)
	return errors.As(c.Insert(friend), *friend)
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:12,代码来源:friend.go

示例10: 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:wxaxiaoyao,项目名称:linux,代码行数:14,代码来源:team.go

示例11: GetUserState

func GetUserState(uid uint64) (*UserState, error) {
	us := &UserState{Uid: uid}
	key := fmt.Sprintf("user_state_%v", us.Uid)
	val, err := redis_.Get(key)
	if err != nil {
		if errors.ERR_NO_DATA.Equal(err) {
			return us, nil
		}
		return us, errors.As(err, key)
	}
	if err := json.Unmarshal([]byte(val), us); err != nil {
		return us, errors.As(err, val)
	}
	return us, nil
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:15,代码来源:state.go

示例12: SetUserDetailInfo

func SetUserDetailInfo(sel, set map[string]interface{}) error {
	c := common.MongoCollection("dudb", "user_detail_info")
	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_detail.go

示例13: 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:wxaxiaoyao,项目名称:linux,代码行数:7,代码来源:user.go

示例14: 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 := redis.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:wxaxiaoyao,项目名称:linux,代码行数:25,代码来源:friend.go

示例15: ExecRet

func ExecRet(sqlStr string, args ...interface{}) (uint64, error) {
	sqlDB := Get()
	defer Put(sqlDB)

	ret, err := sqlDB.Exec(sqlStr, args...)
	if err != nil {
		return 0, errors.As(err, sqlStr, args)
	}

	id, err := ret.LastInsertId()
	if err != nil {
		return 0, errors.As(err, sqlStr, args)
	}

	return uint64(id), nil
}
开发者ID:sunyuantao,项目名称:windows,代码行数:16,代码来源:mysql.go


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