Перевод на int64
This commit is contained in:
parent
b129ea6a81
commit
424a555d16
@ -11,12 +11,12 @@ const (
|
||||
)
|
||||
|
||||
type AclBit struct {
|
||||
Acl uint64
|
||||
Acl int64
|
||||
Atr string
|
||||
}
|
||||
|
||||
// Initialize acl bits and atributes
|
||||
func NewAclBit(def uint64, atr string) *AclBit {
|
||||
func NewAclBit(def int64, atr string) *AclBit {
|
||||
acl := new(AclBit)
|
||||
|
||||
acl.Acl = def
|
||||
@ -26,14 +26,14 @@ func NewAclBit(def uint64, atr string) *AclBit {
|
||||
}
|
||||
|
||||
// Set acl bits and atributes
|
||||
func (a *AclBit) Set(acl uint64, atr string) {
|
||||
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 uint64
|
||||
var endacl int64
|
||||
var endatr string
|
||||
lenacl := len(acl)
|
||||
for _, a0 := range acl {
|
||||
@ -51,7 +51,7 @@ func (a *AclBit) SetArray(acl []AclBit) {
|
||||
}
|
||||
|
||||
// set acl bits
|
||||
func (a *AclBit) SetAcl(acl uint64) {
|
||||
func (a *AclBit) SetAcl(acl int64) {
|
||||
a.Acl = acl
|
||||
}
|
||||
|
||||
@ -66,18 +66,18 @@ func (a *AclBit) Get() *AclBit {
|
||||
}
|
||||
|
||||
// set acl bit in true
|
||||
func (a *AclBit) SetBitTrue(n int) {
|
||||
func (a *AclBit) SetBitTrue(n int64) {
|
||||
a.Acl = a.Acl | (1 << n)
|
||||
}
|
||||
|
||||
// set acl bit in false
|
||||
func (a *AclBit) SetBitFalse(n int) {
|
||||
func (a *AclBit) SetBitFalse(n int64) {
|
||||
a.Acl = a.Acl &^ (1 << n)
|
||||
}
|
||||
|
||||
// get acl bit return true or false
|
||||
func (a *AclBit) GetBit(n int) bool {
|
||||
var msk uint64 = 1 << n
|
||||
func (a *AclBit) GetBit(n int64) bool {
|
||||
var msk int64 = 1 << n
|
||||
if (a.Acl & msk) == msk {
|
||||
return true
|
||||
} else {
|
||||
@ -88,14 +88,14 @@ func (a *AclBit) GetBit(n int) bool {
|
||||
|
||||
// converting acl bits in string
|
||||
func (a *AclBit) StringAcl() string {
|
||||
return strconv.FormatUint(uint64(a.Acl), 2)
|
||||
return strconv.FormatInt(int64(a.Acl), 2)
|
||||
}
|
||||
|
||||
// converting string bits to uint64
|
||||
func Uint64(str string) (uint64, error) {
|
||||
u64, err := strconv.ParseUint(str, 2, 64)
|
||||
// converting string bits to int64
|
||||
func ConvertToInt(str string) (int64, error) {
|
||||
i64, err := strconv.ParseInt(str, 2, 64)
|
||||
if err != nil {
|
||||
return 0, errors.New("string not bit formats")
|
||||
}
|
||||
return u64, nil
|
||||
return i64, nil
|
||||
}
|
||||
|
5
main.go
5
main.go
@ -11,7 +11,7 @@ func main() {
|
||||
acl2 := acl.NewAclBit(2, acl.NullAttr)
|
||||
acl3 := acl.NewAclBit(1, "finance")
|
||||
acl4 := acl.NewAclBit(8, "nofinance")
|
||||
a := make([]acl.AclBit, 0)
|
||||
var a []acl.AclBit
|
||||
a = append(a, *acl1, *acl2, *acl3, *acl4)
|
||||
|
||||
// randoms := 0
|
||||
@ -25,5 +25,8 @@ func main() {
|
||||
aclend.SetArray(a)
|
||||
fmt.Println(aclend.StringAcl())
|
||||
fmt.Println(aclend.Atr)
|
||||
fmt.Println(aclend.GetBit(0))
|
||||
fmt.Println(aclend.GetBit(1))
|
||||
fmt.Println(aclend.GetBit(2))
|
||||
fmt.Println(aclend.GetBit(3))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user