From b444857e82bd341d416e402c1d6c3c00bf3af681 Mon Sep 17 00:00:00 2001 From: zhedazijingang Date: Thu, 28 Aug 2025 15:17:02 +0800 Subject: [PATCH] refactor: use slices.Contains to simplify Signed-off-by: zhedazijingang --- pkg/cid/cid.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/cid/cid.go b/pkg/cid/cid.go index a6812e5..6539ecc 100644 --- a/pkg/cid/cid.go +++ b/pkg/cid/cid.go @@ -11,6 +11,7 @@ import ( "encoding/hex" "encoding/pem" "fmt" + "slices" "github.com/hyperledger/fabric-chaincode-go/v2/pkg/attrmgr" "github.com/hyperledger/fabric-protos-go-apiv2/msp" @@ -143,12 +144,7 @@ func (c *ClientID) HasOUValue(OUValue string) (bool, error) { return false, fmt.Errorf("cannot obtain an X509 certificate for the identity") } - for _, OU := range x509Cert.Subject.OrganizationalUnit { - if OU == OUValue { - return true, nil - } - } - return false, nil + return slices.Contains(x509Cert.Subject.OrganizationalUnit, OUValue), nil } // GetX509Certificate returns the X509 certificate associated with the client,