本文整理汇总了Golang中euphoria/io/heim/proto.UserID.String方法的典型用法代码示例。如果您正苦于以下问题:Golang UserID.String方法的具体用法?Golang UserID.String怎么用?Golang UserID.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类euphoria/io/heim/proto.UserID
的用法示例。
在下文中一共展示了UserID.String方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: banAgent
func (rb *ManagedRoomBinding) banAgent(ctx scope.Context, agentID proto.UserID, until time.Time) error {
ban := &BannedAgent{
AgentID: agentID.String(),
Room: sql.NullString{
String: rb.Name,
Valid: true,
},
Created: time.Now(),
Expires: gorp.NullTime{
Time: until,
Valid: !until.IsZero(),
},
}
// Loop within transaction in read committed mode to simulate UPSERT.
t, err := rb.DbMap.Begin()
if err != nil {
return err
}
for {
// Try to insert; if this fails due to duplicate key value, try to update.
if err := rb.DbMap.Insert(ban); err != nil {
if !strings.HasPrefix(err.Error(), "pq: duplicate key value") {
rollback(ctx, t)
return err
}
} else {
break
}
n, err := rb.DbMap.Update(ban)
if err != nil {
rollback(ctx, t)
return err
}
if n > 0 {
break
}
}
bounceEvent := &proto.BounceEvent{Reason: "banned", AgentID: agentID}
if err := rb.broadcast(ctx, t, proto.BounceEventType, bounceEvent); err != nil {
rollback(ctx, t)
return err
}
if err := t.Commit(); err != nil {
return err
}
return nil
}
示例2: banAgent
func (rb *RoomBinding) banAgent(ctx scope.Context, agentID proto.UserID, until time.Time) error {
ban := &BannedAgent{
AgentID: agentID.String(),
Room: sql.NullString{
String: rb.Name,
Valid: true,
},
Created: time.Now(),
Expires: gorp.NullTime{
Time: until,
Valid: !until.IsZero(),
},
}
if err := rb.DbMap.Insert(ban); err != nil {
return err
}
bounceEvent := &proto.BounceEvent{Reason: "banned", AgentID: agentID.String()}
return rb.broadcast(ctx, rb.Room, proto.BounceEventType, bounceEvent)
}
示例3: unbanAgent
func (rb *ManagedRoomBinding) unbanAgent(ctx scope.Context, agentID proto.UserID) error {
_, err := rb.DbMap.Exec(
"DELETE FROM banned_agent WHERE agent_id = $1 AND room = $2", agentID.String(), rb.Name)
return err
}
示例4: unbanAgent
func (b *Backend) unbanAgent(ctx scope.Context, rb *RoomBinding, agentID proto.UserID) error {
switch rb {
case global:
_, err := b.DbMap.Exec("DELETE FROM banned_agent WHERE room IS NULL AND agent_id = $1", agentID.String())
return err
default:
_, err := b.DbMap.Exec("DELETE FROM banned_agent WHERE room = $1 AND agent_id = $2", rb.RoomName, agentID.String())
return err
}
}