Skip to content

Commit b399dff

Browse files
committed
fix: Resolve lint issues surfaced by Go 1.26.2 and golangci-lint v2.11.4
- Migrate proxy.Director to proxy.Rewrite (deprecated since Go 1.26) - Use fmt.Fprintf instead of WriteString(fmt.Sprintf(...)) - Exclude noctx linter for test files (httptest.NewRequest creates a valid context; requiring WithContext in tests is noise) - Remove now-unused nolint:noctx directive in bench test - Add nolint:prealloc for defensive-copy test
1 parent df169a3 commit b399dff

7 files changed

Lines changed: 23 additions & 22 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ linters:
8888
- err113 # Tests need dynamic errors to test error pattern matching
8989
- funlen # Tests can be verbose with setup/assertions
9090
- cyclop # Tests can have complex control flow
91+
- noctx # httptest.NewRequest creates a valid context; requiring WithContext in tests is noise
9192

9293
# Allow context-as-argument after *testing.T in test helper functions
9394
- path: _test\.go

services/api-gateway/proxy.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,29 @@ func NewProxyHandler(backends []BackendRoute) *ProxyHandler {
6565
// Consider adding configurable timeout settings for production resilience:
6666
// ResponseHeaderTimeout, IdleConnTimeout, MaxIdleConnsPerHost
6767

68-
// Configure the proxy director to add X-Forwarded-Host and identity headers.
68+
// Configure the proxy rewrite to add X-Forwarded-Host and identity headers.
6969
// Connect protocol headers (Content-Type, Connect-Protocol-Version, Connect-Timeout-Ms)
7070
// are standard headers (not hop-by-hop) and are preserved by httputil.ReverseProxy.
71-
originalDirector := proxy.Director
72-
proxy.Director = func(req *http.Request) {
73-
originalDirector(req)
74-
// Set X-Forwarded-Host so backends know the original Host header
75-
if req.Header.Get("X-Forwarded-Host") == "" {
76-
req.Header.Set("X-Forwarded-Host", req.Host)
71+
proxy.Rewrite = func(r *httputil.ProxyRequest) {
72+
r.SetURL(target)
73+
r.SetXForwarded()
74+
// Preserve the original Host header for X-Forwarded-Host
75+
if r.Out.Header.Get("X-Forwarded-Host") == "" {
76+
r.Out.Header.Set("X-Forwarded-Host", r.In.Host)
7777
}
7878

7979
// SECURITY: Strip any incoming identity headers to prevent spoofing.
8080
// These headers are set only by the gateway after successful authentication.
81-
req.Header.Del(HeaderUserID)
82-
req.Header.Del(HeaderTenantID)
83-
req.Header.Del(HeaderAuthMethod)
84-
req.Header.Del(HeaderAuthRoles)
81+
r.Out.Header.Del(HeaderUserID)
82+
r.Out.Header.Del(HeaderTenantID)
83+
r.Out.Header.Del(HeaderAuthMethod)
84+
r.Out.Header.Del(HeaderAuthRoles)
8585

8686
// SECURITY: Strip X-API-Key header to prevent credential leakage to backends.
87-
req.Header.Del(auth.APIKeyHeader)
87+
r.Out.Header.Del(auth.APIKeyHeader)
8888

8989
// Add identity headers if the request was authenticated
90-
addIdentityHeaders(req)
90+
addIdentityHeaders(r.Out)
9191
}
9292

9393
routes = append(routes, proxyRoute{

services/api-gateway/transcoding_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func startBenchEnv(b *testing.B, backends []ServiceBackend) *benchEnv {
117117
AtMost(5 * time.Second).
118118
PollInterval(20 * time.Millisecond).
119119
Until(func() bool {
120-
resp, e := http.Get(baseURL + "/health") //nolint:noctx // Health check in benchmark setup does not need request context
120+
resp, e := http.Get(baseURL + "/health")
121121
if e != nil {
122122
return false
123123
}

services/control-plane/internal/generator/handler_reference.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func BuildHandlerReferenceCard(registry *schema.Registry) string {
4848
return handlers[i].fullName < handlers[j].fullName
4949
})
5050

51-
sb.WriteString(fmt.Sprintf("### %s\n\n", svc))
51+
fmt.Fprintf(&sb, "### %s\n\n", svc)
5252

5353
for _, h := range handlers {
5454
writeHandlerEntry(&sb, h.fullName, h.def)

services/control-plane/internal/generator/llm_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ func buildFixPrompt(manifest string, errors []ValidationError) string {
212212
b.WriteString("## Validation Errors\n\n")
213213

214214
for i, e := range errors {
215-
b.WriteString(fmt.Sprintf("%d. **[%s]** at `%s`\n", i+1, e.Code, e.Path))
216-
b.WriteString(fmt.Sprintf(" - Message: %s\n", e.Message))
215+
fmt.Fprintf(&b, "%d. **[%s]** at `%s`\n", i+1, e.Code, e.Path)
216+
fmt.Fprintf(&b, " - Message: %s\n", e.Message)
217217
if e.Suggestion != "" {
218-
b.WriteString(fmt.Sprintf(" - Suggestion: %s\n", e.Suggestion))
218+
fmt.Fprintf(&b, " - Suggestion: %s\n", e.Suggestion)
219219
}
220220
if len(e.AvailableFields) > 0 {
221-
b.WriteString(fmt.Sprintf(" - Available values: %s\n", strings.Join(e.AvailableFields, ", ")))
221+
fmt.Fprintf(&b, " - Available values: %s\n", strings.Join(e.AvailableFields, ", "))
222222
}
223223
}
224224

services/control-plane/internal/generator/topic_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func BuildTopicList() string {
3535
topicList := byService[svc]
3636
sort.Strings(topicList)
3737

38-
sb.WriteString(fmt.Sprintf("### %s\n\n", svc))
38+
fmt.Fprintf(&sb, "### %s\n\n", svc)
3939
for _, topic := range topicList {
4040
desc := describeTopicName(topic)
41-
sb.WriteString(fmt.Sprintf("- `%s` %s\n", topic, desc))
41+
fmt.Fprintf(&sb, "- `%s` - %s\n", topic, desc)
4242
}
4343
sb.WriteString("\n")
4444
}

services/position-keeping/domain/transaction_lineage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestTransactionLineage_DefensiveCopy_Related(t *testing.T) {
167167
func TestTransactionLineage_Constructor_DefensiveCopy(t *testing.T) {
168168
// Test that mutating input slices after construction doesn't affect lineage
169169
parentID := uuid.New()
170-
children := []uuid.UUID{uuid.New(), uuid.New()}
170+
children := []uuid.UUID{uuid.New(), uuid.New()} //nolint:prealloc // intentional: testing defensive copy, not building a collection
171171
related := []uuid.UUID{uuid.New()}
172172

173173
lineage, err := NewTransactionLineage(uuid.New(), "payment", &parentID, children, related)

0 commit comments

Comments
 (0)