本文整理汇总了Golang中github.com/tinode/chat/server/store/types.Subscription.User方法的典型用法代码示例。如果您正苦于以下问题:Golang Subscription.User方法的具体用法?Golang Subscription.User怎么用?Golang Subscription.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tinode/chat/server/store/types.Subscription
的用法示例。
在下文中一共展示了Subscription.User方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindSubs
// FindSubs returns a list of users who match given tags, such as "email:[email protected]" or "tel:18003287448".
// Just search the 'users.Tags' for the given tags using respective index.
func (a *RethinkDbAdapter) FindSubs(user t.Uid, query []interface{}) ([]t.Subscription, error) {
// Query may contain redundant records, i.e. the same email twice.
// User could be matched on multiple tags, i.e on email and phone#. Thus the query may
// return duplicate users. Thus the need for distinct.
if rows, err := rdb.DB(a.dbName).Table("users").GetAllByIndex("Tags", query...).Limit(MAX_RESULTS).
Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "Public", "Tags").Distinct().Run(a.conn); err != nil {
return nil, err
} else {
index := make(map[string]struct{})
for _, q := range query {
if tag, ok := q.(string); ok {
index[tag] = struct{}{}
}
}
var user t.User
var sub t.Subscription
var subs []t.Subscription
for rows.Next(&user) {
sub.CreatedAt = user.CreatedAt
sub.UpdatedAt = user.UpdatedAt
sub.User = user.Id
sub.ModeWant, sub.ModeGiven = user.Access.Auth, user.Access.Auth
sub.SetPublic(user.Public)
tags := make([]string, 0, 1)
for _, tag := range user.Tags {
if _, ok := index[tag]; ok {
tags = append(tags, tag)
}
}
sub.Private = tags
subs = append(subs, sub)
}
if err = rows.Err(); err != nil {
return nil, err
}
return subs, nil
}
}