Перевод в uint64 и изменение библиотеки
This commit is contained in:
104
acl/aclbit.go
104
acl/aclbit.go
@@ -1,84 +1,59 @@
|
||||
package acl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
NullAttr string = ""
|
||||
AllAttr string = "*"
|
||||
)
|
||||
// unite slice int to int64
|
||||
func UniteAcl(a []uint64) uint64 {
|
||||
var endacl uint64
|
||||
for _, a0 := range a {
|
||||
endacl = endacl | a0
|
||||
}
|
||||
|
||||
type AclBit struct {
|
||||
Acl int64
|
||||
Atr string
|
||||
return endacl
|
||||
}
|
||||
|
||||
// Initialize acl bits and atributes
|
||||
func NewAclBit(def int64, atr string) *AclBit {
|
||||
acl := new(AclBit)
|
||||
|
||||
acl.Acl = def
|
||||
acl.Atr = atr
|
||||
|
||||
return acl
|
||||
}
|
||||
|
||||
// Set acl bits and atributes
|
||||
func (a *AclBit) Set(acl int64, atr string) {
|
||||
a.Acl = acl
|
||||
a.Atr = atr
|
||||
}
|
||||
|
||||
// Set array acl bits and atributes
|
||||
func (a *AclBit) SetArray(acl []AclBit) {
|
||||
var endacl int64
|
||||
//unite slice atr to string
|
||||
func UniteAtr(atr []string) string {
|
||||
var endatr string
|
||||
lenacl := len(acl)
|
||||
for _, a0 := range acl {
|
||||
endacl = endacl | a0.Acl
|
||||
if a0.Atr != NullAttr {
|
||||
endatr = endatr + a0.Atr
|
||||
if lenacl > 1 {
|
||||
lenatr := len(atr)
|
||||
for _, a0 := range atr {
|
||||
if a0 != "" {
|
||||
endatr = endatr + a0
|
||||
if lenatr > 1 {
|
||||
endatr = endatr + ","
|
||||
}
|
||||
}
|
||||
lenacl--
|
||||
lenatr--
|
||||
}
|
||||
a.Acl = endacl
|
||||
a.Atr = endatr
|
||||
|
||||
return endatr
|
||||
}
|
||||
|
||||
// set acl bits
|
||||
func (a *AclBit) SetAcl(acl int64) {
|
||||
a.Acl = acl
|
||||
}
|
||||
|
||||
// set acl atributes
|
||||
func (a *AclBit) SetAtr(atr string) {
|
||||
a.Atr = atr
|
||||
}
|
||||
|
||||
// get current acl
|
||||
func (a *AclBit) Get() *AclBit {
|
||||
return a
|
||||
// unite number bits to int64
|
||||
func UniteBitsToInt(n ...uint64) uint64 {
|
||||
var i64 uint64
|
||||
for _, n0 := range n {
|
||||
i64 = SetBitTrue(i64, n0)
|
||||
}
|
||||
return i64
|
||||
}
|
||||
|
||||
// set acl bit in true
|
||||
func (a *AclBit) SetBitTrue(n int64) {
|
||||
a.Acl = a.Acl | (1 << n)
|
||||
func SetBitTrue(a, n uint64) uint64 {
|
||||
return a | (1 << n)
|
||||
}
|
||||
|
||||
// set acl bit in false
|
||||
func (a *AclBit) SetBitFalse(n int64) {
|
||||
a.Acl = a.Acl &^ (1 << n)
|
||||
func SetBitFalse(a, n uint64) uint64 {
|
||||
return a &^ (1 << n)
|
||||
}
|
||||
|
||||
// get acl bit return true or false
|
||||
func (a *AclBit) GetBit(n int64) bool {
|
||||
var msk int64 = 1 << n
|
||||
if (a.Acl & msk) == msk {
|
||||
// verify bit return true or false
|
||||
func VerifyBit(a, n uint64) bool {
|
||||
var msk uint64 = 1 << n
|
||||
if (a & msk) == msk {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@@ -86,16 +61,17 @@ func (a *AclBit) GetBit(n int64) bool {
|
||||
|
||||
}
|
||||
|
||||
// converting acl bits in string
|
||||
func (a *AclBit) StringAcl() string {
|
||||
return strconv.FormatInt(int64(a.Acl), 2)
|
||||
// converting acl bits to string
|
||||
func ConvertToString(a uint64) string {
|
||||
return strconv.FormatUint(a, 2)
|
||||
}
|
||||
|
||||
// converting string bits to int64
|
||||
func ConvertToInt(str string) (int64, error) {
|
||||
i64, err := strconv.ParseInt(str, 2, 64)
|
||||
func ConvertToInt(str string) *uint64 {
|
||||
ui64, err := strconv.ParseUint(str, 2, 64)
|
||||
if err != nil {
|
||||
return 0, errors.New("string not bit formats")
|
||||
return nil
|
||||
}
|
||||
return i64, nil
|
||||
|
||||
return &ui64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user