From 424a555d1652d0eb5efd219230161d64d602c023 Mon Sep 17 00:00:00 2001 From: Anatoly Prohacky Date: Thu, 4 Aug 2022 18:49:45 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20int64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acl/aclbit.go | 28 ++++++++++++++-------------- main.go | 5 ++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/acl/aclbit.go b/acl/aclbit.go index 2aa4cda..cff5ad1 100644 --- a/acl/aclbit.go +++ b/acl/aclbit.go @@ -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 } diff --git a/main.go b/main.go index 1fa66f5..8160319 100644 --- a/main.go +++ b/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)) }