From eda0f6f4b830eabc969ed986e282f045f624fe29 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:41:46 +0300 Subject: [PATCH 1/9] Wrap errors, use errors.New, merge errors --- pkg/attribute/attribute.go | 6 +++--- pkg/balancer/errors.go | 6 +++--- pkg/balancer/hashring.go | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/attribute/attribute.go b/pkg/attribute/attribute.go index 63c79c48d..38f5de924 100644 --- a/pkg/attribute/attribute.go +++ b/pkg/attribute/attribute.go @@ -56,7 +56,7 @@ func Attribute(attribute string) (*base.Attribute, error) { case "boolean": boolVal, err := strconv.ParseBool(v[1]) if err != nil { - return nil, fmt.Errorf("failed to parse boolean: %v", err) + return nil, fmt.Errorf("failed to parse boolean: %w", err) } wrapped = &base.BooleanValue{Data: boolVal} case "boolean[]": @@ -65,7 +65,7 @@ func Attribute(attribute string) (*base.Attribute, error) { for _, value := range val { boolVal, err := strconv.ParseBool(value) if err != nil { - return nil, fmt.Errorf("failed to parse boolean: %v", err) + return nil, fmt.Errorf("failed to parse boolean: %w", err) } ba = append(ba, boolVal) } @@ -82,7 +82,7 @@ func Attribute(attribute string) (*base.Attribute, error) { case "double": doubleVal, err := strconv.ParseFloat(v[1], 64) if err != nil { - return nil, fmt.Errorf("failed to parse float: %v", err) + return nil, fmt.Errorf("failed to parse float: %w", err) } wrapped = &base.DoubleValue{Data: doubleVal} case "double[]": diff --git a/pkg/balancer/errors.go b/pkg/balancer/errors.go index 25854435e..3d01ed315 100644 --- a/pkg/balancer/errors.go +++ b/pkg/balancer/errors.go @@ -1,12 +1,12 @@ package balancer import ( - "fmt" + "errors" ) var ( // ErrSubConnMissing indicates that a SubConn (sub-connection) was expected but not found. - ErrSubConnMissing = fmt.Errorf("sub-connection is missing or not found") + ErrSubConnMissing = errors.New("sub-connection is missing or not found") // ErrSubConnResetFailure indicates an error occurred while trying to reset the SubConn. - ErrSubConnResetFailure = fmt.Errorf("failed to reset the sub-connection") + ErrSubConnResetFailure = errors.New("failed to reset the sub-connection") ) diff --git a/pkg/balancer/hashring.go b/pkg/balancer/hashring.go index 4855f6206..6a529d161 100644 --- a/pkg/balancer/hashring.go +++ b/pkg/balancer/hashring.go @@ -1,6 +1,7 @@ package balancer import ( + "errors" "fmt" "log" "log/slog" @@ -86,7 +87,7 @@ func (b *consistentHashBalancer) UpdateClientConnState(s balancer.ClientConnStat // If there are no addresses from the resolver, log an error. if len(s.ResolverState.Addresses) == 0 { - b.ResolverError(fmt.Errorf("produced zero addresses")) + b.ResolverError(errors.New("produced zero addresses")) return balancer.ErrBadResolverState } @@ -206,14 +207,14 @@ func (b *consistentHashBalancer) mergeErrors() error { // If only one of the errors is nil, return the other error. if b.lastConnectionError == nil { - return fmt.Errorf("last resolver error: %v", b.lastResolverError) + return fmt.Errorf("last resolver error: %w", b.lastResolverError) } if b.lastResolverError == nil { - return fmt.Errorf("last connection error: %v", b.lastConnectionError) + return fmt.Errorf("last connection error: %w", b.lastConnectionError) } // If both errors are present, concatenate them. - return fmt.Errorf("last connection error: %v; last resolver error: %v", b.lastConnectionError, b.lastResolverError) + return errors.Join(b.lastConnectionError, b.lastResolverError) } // UpdateSubConnState - From c6e7b818771032c11c935b498df73b4fae5b6f01 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:46:57 +0300 Subject: [PATCH 2/9] Improve efficiency --- pkg/attribute/attribute.go | 31 ++++++++++------------------ pkg/development/coverage/coverage.go | 12 +++++------ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/pkg/attribute/attribute.go b/pkg/attribute/attribute.go index 38f5de924..a418818ce 100644 --- a/pkg/attribute/attribute.go +++ b/pkg/attribute/attribute.go @@ -60,24 +60,20 @@ func Attribute(attribute string) (*base.Attribute, error) { } wrapped = &base.BooleanValue{Data: boolVal} case "boolean[]": - var ba []bool val := strings.Split(v[1], ",") - for _, value := range val { + var ba = make([]bool, len(val)) + for i, value := range val { boolVal, err := strconv.ParseBool(value) if err != nil { return nil, fmt.Errorf("failed to parse boolean: %w", err) } - ba = append(ba, boolVal) + ba[i] = boolVal } wrapped = &base.BooleanArrayValue{Data: ba} case "string": wrapped = &base.StringValue{Data: v[1]} case "string[]": - var sa []string - val := strings.Split(v[1], ",") - for _, value := range val { - sa = append(sa, value) - } + var sa = strings.Split(v[1], ",") wrapped = &base.StringArrayValue{Data: sa} case "double": doubleVal, err := strconv.ParseFloat(v[1], 64) @@ -86,14 +82,14 @@ func Attribute(attribute string) (*base.Attribute, error) { } wrapped = &base.DoubleValue{Data: doubleVal} case "double[]": - var da []float64 val := strings.Split(v[1], ",") - for _, value := range val { + var da = make([]float64, len(val)) + for i, value := range val { doubleVal, err := strconv.ParseFloat(value, 64) if err != nil { return nil, fmt.Errorf("failed to parse float: %v", err) } - da = append(da, doubleVal) + da[i] = doubleVal } wrapped = &base.DoubleArrayValue{Data: da} case "integer": @@ -103,15 +99,14 @@ func Attribute(attribute string) (*base.Attribute, error) { } wrapped = &base.IntegerValue{Data: int32(intVal)} case "integer[]": - - var ia []int32 val := strings.Split(v[1], ",") - for _, value := range val { + var ia = make([]int32, len(val)) + for i, value := range val { intVal, err := strconv.ParseInt(value, 10, 32) if err != nil { return nil, fmt.Errorf("failed to parse integer: %v", err) } - ia = append(ia, int32(intVal)) + ia[i] = int32(intVal) } wrapped = &base.IntegerArrayValue{Data: ia} default: @@ -243,11 +238,7 @@ func AnyToString(any *anypb.Any) string { if err := any.UnmarshalTo(stringVal); err != nil { return "undefined" } - var strs []string - for _, v := range stringVal.GetData() { - strs = append(strs, v) - } - str = strings.Join(strs, ",") + str = strings.Join(stringVal.GetData(), ",") case "type.googleapis.com/base.v1.DoubleValue": doubleVal := &base.DoubleValue{} if err := any.UnmarshalTo(doubleVal); err != nil { diff --git a/pkg/development/coverage/coverage.go b/pkg/development/coverage/coverage.go index a55ad7243..a16407da2 100644 --- a/pkg/development/coverage/coverage.go +++ b/pkg/development/coverage/coverage.go @@ -91,9 +91,9 @@ func Run(shape file.Shape) SchemaCoverageInfo { schemaCoverageInfo := SchemaCoverageInfo{} - var refs []SchemaCoverage - for _, en := range definitions { - refs = append(refs, references(en)) + var refs = make([]SchemaCoverage, len(definitions)) + for i, en := range definitions { + refs[i] = references(en) } // Iterate through the schema coverage references @@ -269,8 +269,8 @@ func relationships(en string, relationships []string) []string { // attributes - Get attributes for a given entity func attributes(en string, attributes []string) []string { - var attrs []string - for _, attr := range attributes { + var attrs = make([]string, len(attributes)) + for i, attr := range attributes { a, err := attribute.Attribute(attr) if err != nil { return []string{} @@ -278,7 +278,7 @@ func attributes(en string, attributes []string) []string { if a.GetEntity().GetType() != en { continue } - attrs = append(attrs, fmt.Sprintf("%s#%s", a.GetEntity().GetType(), a.GetAttribute())) + attrs[i] = fmt.Sprintf("%s#%s", a.GetEntity().GetType(), a.GetAttribute()) } return attrs } From b71508fbcc33eb32dbb37e183f33087661e65257 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:47:55 +0300 Subject: [PATCH 3/9] Remove redundant space --- internal/engines/utils.go | 1 - internal/servers/dataServer.go | 1 - pkg/development/development.go | 1 - 3 files changed, 3 deletions(-) diff --git a/internal/engines/utils.go b/internal/engines/utils.go index 170fd5e32..c22834a01 100644 --- a/internal/engines/utils.go +++ b/internal/engines/utils.go @@ -318,7 +318,6 @@ func GenerateKey(key *base.PermissionCheckRequest, isRelational bool) string { if entityRelationString != "" { parts = append(parts, fmt.Sprintf("%s@%s", entityRelationString, subjectString)) } - } else { parts = append(parts, attribute.EntityAndCallOrAttributeToString( key.GetEntity(), diff --git a/internal/servers/dataServer.go b/internal/servers/dataServer.go index e16636c70..585faf3e1 100644 --- a/internal/servers/dataServer.go +++ b/internal/servers/dataServer.go @@ -176,7 +176,6 @@ func (r *DataServer) Write(ctx context.Context, request *v1.DataWriteRequest) (* relationshipsMap := map[string]struct{}{} for _, tup := range request.GetTuples() { - key := tuple.ToString(tup) if _, ok := relationshipsMap[key]; ok { diff --git a/pkg/development/development.go b/pkg/development/development.go index c01a9feeb..ed87b516a 100644 --- a/pkg/development/development.go +++ b/pkg/development/development.go @@ -452,7 +452,6 @@ func (c *Development) RunWithShape(ctx context.Context, shape *file.Shape) (erro // Each SubjectFilter in the current scenario is processed for _, filter := range scenario.SubjectFilters { - subjectReference := tuple.RelationReference(filter.SubjectReference) if err != nil { errors = append(errors, Error{ From 91c7c9d9754ccb82efb70a68947e87cea199875f Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:49:56 +0300 Subject: [PATCH 4/9] Improve the readability --- pkg/dsl/ast/references.go | 10 +++++----- pkg/dsl/lexer/lexer.go | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/dsl/ast/references.go b/pkg/dsl/ast/references.go index 009e95838..0f84ebd44 100644 --- a/pkg/dsl/ast/references.go +++ b/pkg/dsl/ast/references.go @@ -54,7 +54,7 @@ func NewReferences() *References { // AddEntityReference sets a reference for an entity. func (refs *References) AddEntityReference(name string) error { - if len(name) == 0 { + if name == "" { return fmt.Errorf("name cannot be empty") } if refs.IsReferenceExist(name) { @@ -67,7 +67,7 @@ func (refs *References) AddEntityReference(name string) error { // AddRuleReference sets a reference for a rule. func (refs *References) AddRuleReference(name string, types map[string]string) error { - if len(name) == 0 { + if name == "" { return fmt.Errorf("name cannot be empty") } if refs.IsReferenceExist(name) { @@ -80,7 +80,7 @@ func (refs *References) AddRuleReference(name string, types map[string]string) e // AddRelationReferences sets references for a relation with its types. func (refs *References) AddRelationReferences(key string, types []RelationTypeStatement) error { - if len(key) == 0 { + if key == "" { return fmt.Errorf("key cannot be empty") } if refs.IsReferenceExist(key) { @@ -93,7 +93,7 @@ func (refs *References) AddRelationReferences(key string, types []RelationTypeSt // AddPermissionReference sets a reference for a permission. func (refs *References) AddPermissionReference(key string) error { - if len(key) == 0 { + if key == "" { return fmt.Errorf("key cannot be empty") } if refs.IsReferenceExist(key) { @@ -106,7 +106,7 @@ func (refs *References) AddPermissionReference(key string) error { // AddAttributeReferences sets references for an attribute with its type. func (refs *References) AddAttributeReferences(key string, typ AttributeTypeStatement) error { - if len(key) == 0 { + if key == "" { return fmt.Errorf("key cannot be empty") } if refs.IsReferenceExist(key) { diff --git a/pkg/dsl/lexer/lexer.go b/pkg/dsl/lexer/lexer.go index 2b881d09f..d6984e427 100644 --- a/pkg/dsl/lexer/lexer.go +++ b/pkg/dsl/lexer/lexer.go @@ -122,17 +122,18 @@ func (l *Lexer) NextToken() (tok token.Token) { case 0: tok = token.Token{PositionInfo: positionInfo(l.linePosition, l.columnPosition), Type: token.EOF, Literal: ""} case '/': - if l.peekChar() == '/' { + switch l.peekChar() { + case '/': tok.PositionInfo = positionInfo(l.linePosition, l.columnPosition) tok.Literal = l.lexSingleLineComment() tok.Type = token.SINGLE_LINE_COMMENT return - } else if l.peekChar() == '*' { + case '*': tok.PositionInfo = positionInfo(l.linePosition, l.columnPosition) tok.Literal = l.lexMultiLineComment() tok.Type = token.MULTI_LINE_COMMENT return - } else { + default: tok = token.New(positionInfo(l.linePosition, l.columnPosition), token.DIVIDE, l.ch) } case '"': From c1d6796c595452964dc08030e39c58563b5da4d2 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:51:08 +0300 Subject: [PATCH 5/9] Fix: returns nil even if error not nil --- pkg/cmd/migrate.go | 2 +- pkg/schema/loader.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/migrate.go b/pkg/cmd/migrate.go index e934233ee..3f500213d 100644 --- a/pkg/cmd/migrate.go +++ b/pkg/cmd/migrate.go @@ -128,7 +128,7 @@ func migrateDown() func(cmd *cobra.Command, args []string) error { p, err := strconv.ParseInt(flags[target], 10, 64) if err != nil { - return nil + return err } if p == 0 { diff --git a/pkg/schema/loader.go b/pkg/schema/loader.go index f7d33b850..b4a3c94b5 100644 --- a/pkg/schema/loader.go +++ b/pkg/schema/loader.go @@ -72,7 +72,7 @@ func determineSchemaType(input string) (Type, error) { valid, err := isFilePath(input) if err != nil { - return Inline, nil + return Inline, err } if valid { return File, nil From 593583d4f5c1ed41ba58decb6146c9acc394d9f0 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:52:24 +0300 Subject: [PATCH 6/9] Calculate the duration better way --- internal/invoke/invoke.go | 6 +++--- internal/servers/dataServer.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/invoke/invoke.go b/internal/invoke/invoke.go index 27782bafa..d4a7f2a22 100644 --- a/internal/invoke/invoke.go +++ b/internal/invoke/invoke.go @@ -191,7 +191,7 @@ func (invoker *DirectInvoker) Check(ctx context.Context, request *base.Permissio }, }, err } - duration := time.Now().Sub(start) + duration := time.Since(start) invoker.checkDurationHistogram.Record(ctx, duration.Microseconds()) // Increase the check count in the response metadata. @@ -276,7 +276,7 @@ func (invoker *DirectInvoker) LookupEntity(ctx context.Context, request *base.Pe resp, err := invoker.lo.LookupEntity(ctx, request) - duration := time.Now().Sub(start) + duration := time.Since(start) invoker.lookupEntityDurationHistogram.Record(ctx, duration.Microseconds()) // Increase the lookup entity count in the metrics. @@ -323,7 +323,7 @@ func (invoker *DirectInvoker) LookupEntityStream(ctx context.Context, request *b resp := invoker.lo.LookupEntityStream(ctx, request, server) - duration := time.Now().Sub(start) + duration := time.Since(start) invoker.lookupEntityDurationHistogram.Record(ctx, duration.Microseconds()) // Increase the lookup entity count in the metrics. diff --git a/internal/servers/dataServer.go b/internal/servers/dataServer.go index 585faf3e1..65bc1561e 100644 --- a/internal/servers/dataServer.go +++ b/internal/servers/dataServer.go @@ -94,7 +94,7 @@ func (r *DataServer) ReadRelationships(ctx context.Context, request *v1.Relation return nil, status.Error(GetStatus(err), err.Error()) } - duration := time.Now().Sub(start) + duration := time.Since(start) r.readRelationshipsHistogram.Record(ctx, duration.Microseconds()) return &v1.RelationshipReadResponse{ @@ -140,7 +140,7 @@ func (r *DataServer) ReadAttributes(ctx context.Context, request *v1.AttributeRe return nil, status.Error(GetStatus(err), err.Error()) } - duration := time.Now().Sub(start) + duration := time.Since(start) r.readAttributesHistogram.Record(ctx, duration.Microseconds()) return &v1.AttributeReadResponse{ @@ -240,7 +240,7 @@ func (r *DataServer) Write(ctx context.Context, request *v1.DataWriteRequest) (* return nil, status.Error(GetStatus(err), err.Error()) } - duration := time.Now().Sub(start) + duration := time.Since(start) r.writeDataHistogram.Record(ctx, duration.Microseconds()) return &v1.DataWriteResponse{ From 20e4d8e2709e007858c378f94746b0ce05fd8c4f Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:54:17 +0300 Subject: [PATCH 7/9] Define context as the first input of the function --- internal/authn/oidc/authn.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/authn/oidc/authn.go b/internal/authn/oidc/authn.go index 444370a7c..6b7dfa529 100644 --- a/internal/authn/oidc/authn.go +++ b/internal/authn/oidc/authn.go @@ -132,7 +132,7 @@ func (oidc *Authn) Authenticate(requestContext context.Context) error { // Retrieve the key ID from the JWT header and find the corresponding key in the JWKS. if keyID, ok := token.Header["kid"].(string); ok { - return oidc.getKeyWithRetry(keyID, requestContext) + return oidc.getKeyWithRetry(requestContext, keyID) } slog.Error("jwt does not contain a key ID") // If the JWT does not contain a key ID, return an error. @@ -188,7 +188,7 @@ func (oidc *Authn) Authenticate(requestContext context.Context) error { } // getKeyWithRetry attempts to retrieve the key for the given keyID with retries using a custom backoff strategy. -func (oidc *Authn) getKeyWithRetry(keyID string, ctx context.Context) (interface{}, error) { +func (oidc *Authn) getKeyWithRetry(ctx context.Context, keyID string) (interface{}, error) { var rawKey interface{} var err error @@ -207,7 +207,7 @@ func (oidc *Authn) getKeyWithRetry(keyID string, ctx context.Context) (interface oidc.mu.Unlock() // Try to fetch the keyID once - rawKey, err = oidc.fetchKey(keyID, ctx) + rawKey, err = oidc.fetchKey(ctx, keyID) if err == nil { oidc.mu.Lock() if _, ok := oidc.globalRetryKeyIds[keyID]; ok { @@ -232,7 +232,7 @@ func (oidc *Authn) getKeyWithRetry(keyID string, ctx context.Context) (interface // Retry mechanism retries := 0 for retries <= oidc.backoffMaxRetries { - rawKey, err = oidc.fetchKey(keyID, ctx) + rawKey, err = oidc.fetchKey(ctx, keyID) if err == nil { if retries != 0 { oidc.mu.Lock() @@ -298,7 +298,7 @@ func (oidc *Authn) getKeyWithRetry(keyID string, ctx context.Context) (interface } // fetchKey attempts to fetch the JWKS and retrieve the key for the given keyID. -func (oidc *Authn) fetchKey(keyID string, ctx context.Context) (interface{}, error) { +func (oidc *Authn) fetchKey(ctx context.Context, keyID string) (interface{}, error) { // Log the attempt to find the key. slog.DebugContext(ctx, "attempting to find key in JWKS", "kid", keyID) From 03e52fe3cbbe68fa188261f68436d209d70040ea Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:54:42 +0300 Subject: [PATCH 8/9] Set function name to description --- internal/engines/bulk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/engines/bulk.go b/internal/engines/bulk.go index 030bac18c..30487a192 100644 --- a/internal/engines/bulk.go +++ b/internal/engines/bulk.go @@ -123,7 +123,7 @@ func (bc *BulkChecker) CollectAndSortRequests() { } } -// Signal to stop collecting requests and close the channel +// StopCollectingRequests Signal to stop collecting requests and close the channel func (bc *BulkChecker) StopCollectingRequests() { bc.mu.Lock() defer bc.mu.Unlock() From fe68edb7f1413c0349db3b91aa980d8774125810 Mon Sep 17 00:00:00 2001 From: Engin Date: Tue, 27 Aug 2024 18:55:27 +0300 Subject: [PATCH 9/9] Use same receiver name --- internal/engines/bulk.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/engines/bulk.go b/internal/engines/bulk.go index 30487a192..13db0226f 100644 --- a/internal/engines/bulk.go +++ b/internal/engines/bulk.go @@ -145,24 +145,24 @@ func (bc *BulkChecker) sortRequests() { } // ExecuteRequests begins processing permission check requests from the sorted list. -func (c *BulkChecker) ExecuteRequests(size uint32) error { +func (bc *BulkChecker) ExecuteRequests(size uint32) error { // Stop collecting new requests and close the RequestChan to ensure no more requests are added - c.StopCollectingRequests() + bc.StopCollectingRequests() // Wait for request collection to complete before proceeding - c.wg.Wait() + bc.wg.Wait() // Track the number of successful permission checks successCount := int64(0) // Semaphore to control the maximum number of concurrent permission checks - sem := semaphore.NewWeighted(int64(c.concurrencyLimit)) + sem := semaphore.NewWeighted(int64(bc.concurrencyLimit)) var mu sync.Mutex // Lock the mutex to prevent race conditions while sorting and copying the list of requests - c.mu.Lock() - c.sortRequests() // Sort requests based on id - listCopy := append([]BulkCheckerRequest{}, c.list...) // Create a copy of the list to avoid modifying the original during processing - c.mu.Unlock() // Unlock the mutex after sorting and copying + bc.mu.Lock() + bc.sortRequests() // Sort requests based on id + listCopy := append([]BulkCheckerRequest{}, bc.list...) // Create a copy of the list to avoid modifying the original during processing + bc.mu.Unlock() // Unlock the mutex after sorting and copying // Pre-allocate a slice to store the results of the permission checks results := make([]base.CheckResult, len(listCopy)) @@ -180,9 +180,9 @@ func (c *BulkChecker) ExecuteRequests(size uint32) error { req := currentRequest // Use errgroup to manage the goroutines, which allows for error handling and synchronization - c.g.Go(func() error { + bc.g.Go(func() error { // Acquire a slot in the semaphore to control concurrency - if err := sem.Acquire(c.ctx, 1); err != nil { + if err := sem.Acquire(bc.ctx, 1); err != nil { return err // Return an error if semaphore acquisition fails } defer sem.Release(1) // Ensure the semaphore slot is released after processing @@ -190,7 +190,7 @@ func (c *BulkChecker) ExecuteRequests(size uint32) error { var result base.CheckResult if req.Result == base.CheckResult_CHECK_RESULT_UNSPECIFIED { // Perform the permission check if the result is not already specified - cr, err := c.checker.Check(c.ctx, req.Request) + cr, err := bc.checker.Check(bc.ctx, req.Request) if err != nil { return err // Return an error if the check fails } @@ -212,17 +212,17 @@ func (c *BulkChecker) ExecuteRequests(size uint32) error { ct := "" if processedIndex+1 < len(listCopy) { // If there is a next item, create a continuous token with the next ID - if c.typ == BULK_ENTITY { + if bc.typ == BULK_ENTITY { ct = utils.NewContinuousToken(listCopy[processedIndex+1].Request.GetEntity().GetId()).Encode().String() - } else if c.typ == BULK_SUBJECT { + } else if bc.typ == BULK_SUBJECT { ct = utils.NewContinuousToken(listCopy[processedIndex+1].Request.GetSubject().GetId()).Encode().String() } } // Depending on the type of check (entity or subject), call the appropriate callback - if c.typ == BULK_ENTITY { - c.callback(listCopy[processedIndex].Request.GetEntity().GetId(), ct) - } else if c.typ == BULK_SUBJECT { - c.callback(listCopy[processedIndex].Request.GetSubject().GetId(), ct) + if bc.typ == BULK_ENTITY { + bc.callback(listCopy[processedIndex].Request.GetEntity().GetId(), ct) + } else if bc.typ == BULK_SUBJECT { + bc.callback(listCopy[processedIndex].Request.GetSubject().GetId(), ct) } } } @@ -235,7 +235,7 @@ func (c *BulkChecker) ExecuteRequests(size uint32) error { } // Wait for all goroutines to complete and check for any errors - if err := c.g.Wait(); err != nil { + if err := bc.g.Wait(); err != nil { return err // Return the error if any goroutine returned an error }