本文整理匯總了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
}