本文整理汇总了Golang中github.com/couchbase/sync_gateway/auth.User.InheritedChannels方法的典型用法代码示例。如果您正苦于以下问题:Golang User.InheritedChannels方法的具体用法?Golang User.InheritedChannels怎么用?Golang User.InheritedChannels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/sync_gateway/auth.User
的用法示例。
在下文中一共展示了User.InheritedChannels方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: filterViewResult
// Cleans up the Value property, and removes rows that aren't visible to the current user
func filterViewResult(input walrus.ViewResult, user auth.User) (result walrus.ViewResult) {
checkChannels := false
var visibleChannels ch.TimedSet
if user != nil {
visibleChannels = user.InheritedChannels()
checkChannels = !visibleChannels.Contains("*")
}
result.TotalRows = input.TotalRows
result.Rows = make([]*walrus.ViewRow, 0, len(input.Rows)/2)
for _, row := range input.Rows {
value := row.Value.([]interface{})
// value[0] is the array of channels; value[1] is the actual value
if !checkChannels || channelsIntersect(visibleChannels, value[0].([]interface{})) {
// Add this row:
stripSyncProperty(row)
result.Rows = append(result.Rows, &walrus.ViewRow{
Key: row.Key,
Value: value[1],
ID: row.ID,
Doc: row.Doc,
})
}
}
return
}
示例2: makeUserCtx
// Creates a userCtx object to be passed to the sync function
func makeUserCtx(user auth.User) map[string]interface{} {
if user == nil {
return nil
}
return map[string]interface{}{
"name": user.Name(),
"roles": user.RoleNames(),
"channels": user.InheritedChannels().AllChannels(),
}
}
示例3: filterViewResult
// Cleans up the Value property, and removes rows that aren't visible to the current user
func filterViewResult(input sgbucket.ViewResult, user auth.User, applyChannelFiltering bool) (result sgbucket.ViewResult) {
hasStarChannel := false
var visibleChannels ch.TimedSet
if user != nil {
visibleChannels = user.InheritedChannels()
hasStarChannel = !visibleChannels.Contains("*")
if !applyChannelFiltering {
return // this is an error
}
}
result.TotalRows = input.TotalRows
result.Rows = make([]*sgbucket.ViewRow, 0, len(input.Rows)/2)
for _, row := range input.Rows {
if applyChannelFiltering {
value, ok := row.Value.([]interface{})
if ok {
// value[0] is the array of channels; value[1] is the actual value
if !hasStarChannel || channelsIntersect(visibleChannels, value[0].([]interface{})) {
// Add this row:
stripSyncProperty(row)
result.Rows = append(result.Rows, &sgbucket.ViewRow{
Key: row.Key,
Value: value[1],
ID: row.ID,
Doc: row.Doc,
})
}
}
} else {
// Add the raw row:
stripSyncProperty(row)
result.Rows = append(result.Rows, &sgbucket.ViewRow{
Key: row.Key,
Value: row.Value,
ID: row.ID,
Doc: row.Doc,
})
}
}
result.TotalRows = len(result.Rows)
return
}