Conversation
…n env_sources Agent-Logs-Url: https://github.com/Kong/kongctl/sessions/66acfdaf-3733-4ea7-a0bd-4f72a7ac1b52 Co-authored-by: rspurgeon <10521262+rspurgeon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Simplify code in event_gateway_produce_policy.go and env_sources.go
refactor: eliminate redundant JSON unmarshals in produce-policy validators; use slices.Contains in env_sources
Apr 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR streamlines declarative parsing by reducing redundant JSON unmarshalling in the Event Gateway produce policy resource and simplifying struct-tag parsing logic in the loader using standard library slice helpers.
Changes:
- Unmarshal produce policy JSON into a
map[string]anyonce and reuse it across validators (aligning with the existing consume policy pattern). - Simplify produce policy type validation by centralizing allowed types in a single slice and using
slices.Contains. - Replace a manual
"inline"tag scan loop withslices.Containsin structured tag parsing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/declarative/resources/event_gateway_produce_policy.go | Parse JSON once for validators and simplify allowed-type handling in produce policy unmarshalling/validation. |
| internal/declarative/loader/env_sources.go | Use slices.Contains to detect "inline" in structured field tags, reducing boilerplate. |
Collaborator
|
@harshadixit12 please review |
harshadixit12
approved these changes
Apr 27, 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.
Two minor simplifications to align recently added code with existing codebase patterns.
Changes
event_gateway_produce_policy.go—UnmarshalJSONwas callingjson.Unmarshal4× (meta struct + 2 validators + SDK union type). Parsedataintomap[string]anyonce after the meta extraction and pass it to both validators, matching the pattern inevent_gateway_consume_policy.go. Also eliminates 3 intermediate string variables (modifyHeadersType,schemaValidationType,encryptType) in favor of directvalidTypesslice indexing.env_sources.go— Replace 3-line manual loop inparseStructuredFieldTagwithslices.Contains(parts[1:], "inline"), consistent with Go 1.26 idioms used throughout the codebase.