本文整理汇总了Golang中github.com/masom/doorbot/doorbot.Repositories.BridgeUserRepository方法的典型用法代码示例。如果您正苦于以下问题:Golang Repositories.BridgeUserRepository方法的具体用法?Golang Repositories.BridgeUserRepository怎么用?Golang Repositories.BridgeUserRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/masom/doorbot/doorbot.Repositories
的用法示例。
在下文中一共展示了Repositories.BridgeUserRepository方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Sync
// Sync doorbot users with a foreign data source using a bridge.
func Sync(render render.Render, r doorbot.Repositories, b bridges.Bridges, a *doorbot.Account, session *auth.Authorization) {
var bUsers []*doorbot.BridgeUser
var registered []*doorbot.BridgeUser
var err error
personRepo := r.PersonRepository()
bUserRepo := r.BridgeUserRepository()
var bridgesToSync = []uint{bridges.BridgeHub, bridges.BridgeHipChat}
for _, bridgeId := range bridgesToSync {
f := func() bool {
users, err := b.GetUsers(bridgeId)
for _, u := range users {
log.WithFields(log.Fields{"user": *u}).Info("User")
}
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": a.ID,
"bridge_id": bridgeId,
}).Error("Api::People->Sync bridge error")
return false
}
existing, err := bUserRepo.FindByBridgeID(r.DB(), bridgeId)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"step": "bridge-user-find-by-bridge-id",
"bridge_id": bridgeId,
}).Error("Api::People->Sync database error")
return false
}
registered = append(registered, existing...)
bUsers = append(bUsers, users...)
return true
}
f()
}
tx, err := r.Transaction()
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"step": "transaction-create",
}).Error("Api::People->Sync database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
var buser *doorbot.BridgeUser
for _, u := range bUsers {
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"bridge_user_id": u.UserID,
"bridge_user_email": u.Email,
"bridge_user_name": u.Name,
}).Debug("Api::People->Sync bridge user")
buser = findRegistered(registered, u.UserID)
if buser != nil {
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"bridge_user_id": buser.UserID,
"person_id": buser.PersonID,
}).Debug("Api::People->Sync registered user found")
person, err := personRepo.Find(tx, buser.PersonID)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"bridge_user_id": buser.UserID,
"person_id": buser.PersonID,
"step": "person-find-from-bridge-id",
}).Error("Api::People->Sync database error")
break
}
person.Name = u.Name
person.Email = u.Email
person.PhoneNumber = u.PhoneNumber
//.........这里部分代码省略.........