本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/privilege.List類的典型用法代碼示例。如果您正苦於以下問題:Golang List類的具體用法?Golang List怎麽用?Golang List使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了List類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Revoke
// Revoke removes privileges from this descriptor for a given list of users.
func (p *PrivilegeDescriptor) Revoke(user string, privList privilege.List) {
userPriv, ok := p.findUser(user)
if !ok || userPriv.Privileges == 0 {
// Removing privileges from a user without privileges is a no-op.
return
}
bits := privList.ToBitField()
if isPrivilegeSet(bits, privilege.ALL) {
// Revoking 'ALL' privilege: remove user.
// TODO(marc): the grammar does not allow it, but we should
// check if other privileges are being specified and error out.
p.removeUser(user)
return
}
if isPrivilegeSet(userPriv.Privileges, privilege.ALL) {
// User has 'ALL' privilege. Remove it and set
// all other privileges one.
userPriv.Privileges = 0
for _, v := range privilege.ByValue {
if v != privilege.ALL {
userPriv.Privileges |= v.Mask()
}
}
}
// One doesn't see "AND NOT" very often.
userPriv.Privileges &^= bits
if userPriv.Privileges == 0 {
p.removeUser(user)
}
}
示例2: NewPrivilegeDescriptor
// NewPrivilegeDescriptor returns a privilege descriptor for the given
// user with the specified list of privileges.
func NewPrivilegeDescriptor(user string, priv privilege.List) *PrivilegeDescriptor {
return &PrivilegeDescriptor{
Users: []UserPrivileges{
{
User: user,
Privileges: priv.ToBitField(),
},
},
}
}
示例3: Grant
// Grant adds new privileges to this descriptor for a given list of users.
// TODO(marc): if all privileges other than ALL are set, should we collapse
// them into ALL?
func (p *PrivilegeDescriptor) Grant(user string, privList privilege.List) {
userPriv := p.findOrCreateUser(user)
if isPrivilegeSet(userPriv.Privileges, privilege.ALL) {
// User already has 'ALL' privilege: no-op.
return
}
bits := privList.ToBitField()
if isPrivilegeSet(bits, privilege.ALL) {
// Granting 'ALL' privilege: overwrite.
// TODO(marc): the grammar does not allow it, but we should
// check if other privileges are being specified and error out.
userPriv.Privileges = privilege.ALL.Mask()
return
}
userPriv.Privileges |= bits
}