Skip to content

refactor: go fix ./... — modernize to Go 1.25 idioms#116

Merged
rsharath merged 1 commit intomainfrom
gofix
May 5, 2026
Merged

refactor: go fix ./... — modernize to Go 1.25 idioms#116
rsharath merged 1 commit intomainfrom
gofix

Conversation

@rsharath
Copy link
Copy Markdown
Contributor

@rsharath rsharath commented May 5, 2026

Summary

Mechanical output of go fix ./... on both the root module and pkg/authjwt. Five categories of pure-form modernization to Go 1.21–1.25 idioms. No API or semantic changes. Net code reduction: 11 files, +41/−71.

What changed

Pattern Before → After Sites
interface{}any (Go 1.18+) type-alias modernization internal/service/{audit,authcode}.go, pkg/authjwt/{claims,verifier_test}.go
for i := 0; i < N; i++for range N (Go 1.22+) integer-range loops tests/integration/{attestation_oidc,deactivation,identity,refresh_token_race}_test.go
manual loop → slices.Contains (Go 1.21+) adds "slices" import in 3 files internal/service/credential_policy.go::containsString, internal/service/oauth.go (3 sites: client_credentials / authorization_code / refresh_token grant-allowlist checks), pkg/authjwt/claims.go::HasScope
if x < 0 { x = 0 }max(x, 0) (Go 1.21+ builtins) offset clamp internal/handler/identity.go::listIdentitiesOp
wg.Add(1) + go func() { defer wg.Done(); ... }()wg.Go(func() { ... }) (Go 1.25) new WaitGroup.Go method tests/integration/refresh_token_race_test.go::TestRefreshTokenConcurrentRotation

The slices.Contains swaps add "slices" to imports in three files — no other import changes.

Test plan

  • go vet ./... — clean (root + pkg/authjwt)
  • go test ./... -count=1 -timeout=180s — green, ~9.8s
  • No semantic changes — pure mechanical output of go fix

Scope and ordering

Why this is worth doing

  • Removes language-version-tax noise from future diffs (every interface{} you see in a future PR review will now be there because someone wrote it post-fix, not because it predates the alias).
  • slices.Contains is more grep-able than ad-hoc loops and harder to get subtly wrong.
  • wg.Go removes the Add(1) / defer Done() pairing footgun in concurrent test code.
  • for range N matches what the project already uses for newer code; consistency.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modernizes the codebase by adopting Go 1.21+ features, such as the max built-in, the slices package for collection checks, and the any alias for interface{}. It also simplifies integer-based loops using the range keyword. However, a critical compilation error was introduced in the integration tests by attempting to use a non-existent Go method on sync.WaitGroup. Additionally, the containsString helper function should be removed as it is now a redundant wrapper around slices.Contains.

Comment thread tests/integration/refresh_token_race_test.go
Comment thread tests/integration/refresh_token_race_test.go
Comment thread internal/service/credential_policy.go Outdated
Mechanical output of go fix ./... on both the root module and pkg/authjwt.
Five categories of pure-form modernization, identical semantics, no API
changes:

1. interface{} → any  (Go 1.18+)
   internal/service/{audit,authcode}.go
   pkg/authjwt/{claims,verifier_test}.go

2. for i := 0; i < N; i++  →  for range N  (Go 1.22+)
   tests/integration/{attestation_oidc,deactivation,identity,refresh_token_race}_test.go

3. manual loop → slices.Contains  (Go 1.21+)
   internal/service/credential_policy.go::containsString
   internal/service/oauth.go (3 sites: client_credentials / authorization_code
                              / refresh_token grant-allowlist checks)
   pkg/authjwt/claims.go::HasScope

4. if x < 0 { x = 0 }  →  max(x, 0)  (Go 1.21+ builtins)
   internal/handler/identity.go::listIdentitiesOp (offset clamp)

5. wg.Add(1) + go func(){defer wg.Done(); ...}()  →  wg.Go(func(){...})  (Go 1.25)
   tests/integration/refresh_token_race_test.go::TestRefreshTokenConcurrentRotation

Net: 11 files, +41/-71. Adds "slices" import in three files; no other
import changes.

Test plan
- [x] go vet ./...                              — clean (root + pkg/authjwt)
- [x] go test ./... -count=1 -timeout=180s      — green, ~9.8s
@rsharath rsharath merged commit 12db8f5 into main May 5, 2026
10 checks passed
@rsharath rsharath deleted the gofix branch May 5, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants