本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/auth.Principal.Channels方法的典型用法代码示例。如果您正苦于以下问题:Golang Principal.Channels方法的具体用法?Golang Principal.Channels怎么用?Golang Principal.Channels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/sync_gateway/auth.Principal
的用法示例。
在下文中一共展示了Principal.Channels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: marshalPrincipal
func marshalPrincipal(princ auth.Principal) ([]byte, error) {
name := externalUserName(princ.Name())
info := PrincipalJSON{
Name: &name,
ExplicitChannels: princ.ExplicitChannels().AsSet(),
Channels: princ.Channels().AsSet(),
}
if user, ok := princ.(auth.User); ok {
info.Email = user.Email()
info.Disabled = user.Disabled()
info.ExplicitRoleNames = user.ExplicitRoleNames()
info.RoleNames = user.RoleNames()
}
return json.Marshal(info)
}
示例2: GetPrincipal
func (dbc *DatabaseContext) GetPrincipal(name string, isUser bool) (info *PrincipalConfig, err error) {
var princ auth.Principal
if isUser {
princ, err = dbc.Authenticator().GetUser(name)
} else {
princ, err = dbc.Authenticator().GetRole(name)
}
if princ == nil {
return
}
info = new(PrincipalConfig)
info.Name = &name
info.ExplicitChannels = princ.ExplicitChannels().AsSet()
if user, ok := princ.(auth.User); ok {
info.Channels = user.InheritedChannels().AsSet()
info.Email = user.Email()
info.Disabled = user.Disabled()
info.ExplicitRoleNames = user.ExplicitRoles().AllChannels()
info.RoleNames = user.RoleNames().AllChannels()
} else {
info.Channels = princ.Channels().AsSet()
}
return
}