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


Golang UserID.Parse方法代码示例

本文整理汇总了Golang中euphoria/io/heim/proto.UserID.Parse方法的典型用法代码示例。如果您正苦于以下问题:Golang UserID.Parse方法的具体用法?Golang UserID.Parse怎么用?Golang UserID.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在euphoria/io/heim/proto.UserID的用法示例。


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

示例1: NotifyUser

func (b *TestBackend) NotifyUser(ctx scope.Context, userID proto.UserID, packetType proto.PacketType, payload interface{}, excluding ...proto.Session) error {
	kind, id := userID.Parse()
	for _, room := range b.rooms {
		mRoom, _ := room.(*memRoom)
		for u, sessList := range mRoom.live {
			for _, sess := range sessList {
				if u == userID || (kind == "agent" && sess.AgentID() == id) {
					if !isExcluded(sess, excluding) {
						if err := sess.Send(ctx, packetType, payload); err != nil {
							return err
						}
					}
				}
			}
		}
	}
	return nil
}
开发者ID:logan,项目名称:heim,代码行数:18,代码来源:backend.go

示例2: NotifyUser

func (lm ListenerMap) NotifyUser(ctx scope.Context, userID proto.UserID, event *proto.Packet, exclude ...string) error {
	excludeSet := map[string]struct{}{}
	for _, exc := range exclude {
		excludeSet[exc] = struct{}{}
	}
	payload, err := event.Payload()
	if err != nil {
		return err
	}
	kind, id := userID.Parse()
	for sessionID, listener := range lm {
		// check that the listener is not excluded
		if _, ok := excludeSet[sessionID]; ok {
			continue
		}

		if listener.Identity().ID() == userID || (kind == "agent" && id == listener.AgentID()) {
			listener.Send(ctx, event.Type, payload)
		}
	}
	return nil
}
开发者ID:logan,项目名称:heim,代码行数:22,代码来源:listener.go

示例3: Initiate

func (t *PMTracker) Initiate(
	ctx scope.Context, kms security.KMS, room proto.Room, client *proto.Client, recipient proto.UserID) (
	snowflake.Snowflake, error) {

	initiatorNick, ok, err := room.ResolveNick(ctx, proto.UserID(fmt.Sprintf("account:%s", client.Account.ID())))
	if err != nil {
		return 0, err
	}
	if !ok {
		initiatorNick = fmt.Sprintf("account:%s", client.Account.ID())
	}

	recipientNick, ok, err := room.ResolveNick(ctx, recipient)
	if err != nil {
		return 0, err
	}
	if !ok {
		recipientNick = string(recipient)
	}

	pm, err := proto.InitiatePM(ctx, t.Backend, kms, client, initiatorNick, recipient, recipientNick)
	if err != nil {
		return 0, err
	}
	row := &PM{
		ID:                    pm.ID.String(),
		Initiator:             pm.Initiator.String(),
		InitiatorNick:         pm.InitiatorNick,
		Receiver:              string(pm.Receiver),
		ReceiverNick:          pm.ReceiverNick,
		ReceiverMAC:           pm.ReceiverMAC,
		IV:                    pm.IV,
		EncryptedSystemKey:    pm.EncryptedSystemKey.Ciphertext,
		EncryptedInitiatorKey: pm.EncryptedInitiatorKey.Ciphertext,
	}
	if pm.EncryptedReceiverKey != nil {
		row.EncryptedReceiverKey = pm.EncryptedReceiverKey.Ciphertext
	}

	// Look for existing PM to reuse.
	tx, err := t.DbMap.Begin()
	if err != nil {
		return 0, err
	}

	var existingRow PM
	err = tx.SelectOne(
		&existingRow,
		"SELECT id FROM pm WHERE initiator = $1 AND receiver = $2",
		client.Account.ID().String(), string(recipient))
	if err != nil && err != sql.ErrNoRows {
		rollback(ctx, tx)
		return 0, err
	}
	if err == nil {
		rollback(ctx, tx)
		var pmID snowflake.Snowflake
		if err := pmID.FromString(existingRow.ID); err != nil {
			return 0, err
		}
		return pmID, nil
	}

	kind, id := recipient.Parse()
	if kind == "account" {
		var existingRow PM
		err = tx.SelectOne(
			&existingRow,
			"SELECT id FROM pm WHERE initiator = $1 AND receiver = $2",
			id, string(client.UserID()))
		if err != nil && err != sql.ErrNoRows {
			rollback(ctx, tx)
			return 0, err
		}
		if err == nil {
			rollback(ctx, tx)
			var pmID snowflake.Snowflake
			if err := pmID.FromString(existingRow.ID); err != nil {
				return 0, err
			}
			return pmID, nil
		}
	}

	if err := tx.Insert(row); err != nil {
		rollback(ctx, tx)
		return 0, err
	}

	if err := tx.Commit(); err != nil {
		return 0, err
	}

	return pm.ID, nil
}
开发者ID:logan,项目名称:heim,代码行数:95,代码来源:pm.go


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