simplify: remove redundant loop-variable copies in eventgateway files#887
Merged
simplify: remove redundant loop-variable copies in eventgateway files#887
Conversation
Agent-Logs-Url: https://github.com/Kong/kongctl/sessions/b9f52eb7-6087-49e7-b84f-8ef060bfd1a0 Co-authored-by: rspurgeon <10521262+rspurgeon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Simplify redundant loop variable copies in eventgateway files
simplify: remove redundant loop-variable copies in eventgateway files
Apr 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes several Event Gateway and adopt helper functions by removing now-unnecessary per-iteration struct copies when returning pointers from range loops, aligning the code with the repository’s Go 1.26 toolchain semantics.
Changes:
- Removed redundant
xCopy := xpatterns in multiplefind*ByNamehelpers and inresolveEventGatewayControlPlane. - Continued to return pointers to per-iteration
rangevariables (maintaining the prior “pointer to copy” behavior without extra locals).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/root/products/konnect/eventgateway/backend_clusters.go | Removes redundant loop-variable copy in backend cluster lookup helper. |
| internal/cmd/root/products/konnect/eventgateway/virtual_clusters.go | Removes redundant loop-variable copies in virtual cluster lookup helper. |
| internal/cmd/root/products/konnect/eventgateway/listeners.go | Removes redundant loop-variable copy in listener lookup helper. |
| internal/cmd/root/products/konnect/eventgateway/data_plane_certificates.go | Removes redundant loop-variable copy in data plane certificate lookup helper. |
| internal/cmd/root/products/konnect/eventgateway/cluster-policies.go | Removes redundant loop-variable copy in cluster policy lookup helper. |
| internal/cmd/root/products/konnect/adopt/event_gateway.go | Removes redundant loop-variable copy when selecting an EGW control plane by name. |
harshadixit12
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Go 1.22+, each range-loop iteration owns its variable, making
xCopy := x; return &xCopydead code. Six functions across the eventgateway and adopt packages used this pattern unnecessarily.Changes
findClusterByName(backend_clusters.go) — 2 copies removedfindVirtualClusterByName(virtual_clusters.go) — 2 copies removedfindListenerByName(listeners.go) — 1 copy removedfindDataPlaneCertByName(data_plane_certificates.go) — 1 copy removedfindClusterPolicyByName(cluster-policies.go) — 1 copy removedresolveEventGatewayControlPlane(adopt/event_gateway.go) — 1 copy removedBefore:
After:
No functional change — aligns with the Go 1.26 modernization standard in
AGENTS.md.