Kong / Kong/kongctl

[simplifier] Go 1.26 modernization and cleanup in planner and dump packages

Open
#2,222 0 comments 0 reactions 0 assignees View on GitHub
refactoring
Dominant language
Go
Stars
17
Forks
24
Avg merge
8h 13m
Merged PRs (30d)
196

Description

Code merged in the last 24 hours (PRs #2201, #2208) introduced or
preserved patterns that can be simplified using Go 1.26 stdlib and
general cleanup. All items below are mechanical, behavior-preserving
changes.

---

### 1. Replace `compareStringSlices` with `slices.Equal`

**File:** `internal/declarative/planner/event_gateway_backend_cluster_planner.go` lines 480-489

The manual loop is equivalent to `slices.Equal(a, b)`. Per AGENTS.md
Go 1.26 modernization standards, the `slices` package should be used
instead of manual loops.

```go
// Before
func compareStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}

// After: inline slices.Equal at call sites and remove the function
// Callers in event_gateway_listener_planner.go and
// event_gateway_backend_cluster_planner.go become:
// slices.Equal(current.Addresses, desired.Addresses)
```

**Callers (3):**
- `event_gateway_backend_cluster_planner.go:365`
- `event_gateway_listener_planner.go:476`
- `event_gateway_listener_planner.go:488`

---

### 2. Replace `compareStringMaps` with `maps.Equal`

**File:** `internal/declarative/planner/event_gateway_backend_cluster_planner.go` lines 512-522

Same rationale. The manual map comparison is `maps.Equal(a, b)`.

```go
// Before
func compareStringMaps(a, b map[string]string) bool { ... }

// After: inline maps.Equal at call sites and remove the function
```

**Callers (2):**
- `event_gateway_backend_cluster_planner.go:406`
- `event_gateway_static_key_planner.go:292`

---

### 3. Remove redundant `reflect.Kind` case listing in `isEmptyValue`

**File:** `internal/cmd/root/verbs/dump/declarative.go` lines 967-986

The exhaustive listing of `reflect.Invalid`, `reflect.Bool`, ...,
`reflect.UnsafePointer` all return `false`, which is identical to the
`return false` default at line 989. The 17-line case block can be
deleted with no behavior change.

---

### 4. Hoist compiled regex out of `isValidHostname`

**File:** `internal/declarative/resources/portal_custom_domain.go` lines 137-143

`regexp.MustCompile` is called on every invocation. Move the compiled
regex to a package-level variable so it is compiled once at init time.

```go
// Before
func isValidHostname(hostname string) bool {
pattern := `^...`
hostnameRegex := regexp.MustCompile(pattern)
return hostnameRegex.MatchString(hostname)
}

// After
var hostnameRegex = regexp.MustCompile(
`^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*` +
`[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$`,
)

func isValidHostname(hostname string) bool {
return hostnameRegex.MatchString(hostname)
}
```

---

### Validation steps

After applying changes, run:

```sh
go fix ./...
make format
make build
make lint
make test
```

> Generated by [Code Simplifier](https://github.com/Kong/kongctl/actions/runs/35300741437) · opus46 · 236.5 AIC · ⌖ 29.4 AIC · ⊞ 5.9K · [◷](https://github.com/search?q=repo%3AKong%2Fkongctl+is%3Aissue+%22gh-aw-workflow-call-id%3A+Kong%2Fkongctl%2Fcode-simplifier%22&type=issues)
>

Add this agentic workflow to your repo

To install this agentic workflow, run

```
gh aw add githubnext/agentics/workflows/code-simplifier.md@eb7950f37d350af6fa09d19827c4883e72947221
```

> - [x] expires on Sep 23, 2026, 2:57 AM UTC

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the listed planner files, internal/cmd/root/verbs/dump/declarative.go, and internal/declarative/resources/portal_custom_domain.go; read the named functions and their callers. Apply the specified Go 1.26 simplifications while preserving behavior, then run go fix ./..., make format, make build, make lint, and make test. Done means all four cleanup items are addressed and validation passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, tooling
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.