DUP-GO-3: 4 read-adapter session handlers share identical withSessionAdapter pattern #42

Closed
opened 2026-05-27 16:56:57 +02:00 by dries · 0 comments
Owner

Summary

Four handlers in internal/server/handlers_sessions.go are structurally identical 11-line functions:

  • handleSessionAgents (lines 400–412)
  • handleSessionCommands (lines 414–426)
  • handleSessionPermissions (lines 442–454)
  • handleSessionQuestions (lines 456–468)

Pattern

Each calls withSessionAdapter, invokes the adapter method, nil-guards the result slice, and calls writeJSON. The only variation is the adapter method, the error message string, and the empty-slice type.

Fix

Could use Go generics (func handleSessionCollection[T any](...)) to collapse all four into a single generic handler. At minimum, the nil-guard pattern should be extracted.

Effort

Medium (full generic refactor); Low (nil-guard extraction only).

## Summary Four handlers in `internal/server/handlers_sessions.go` are structurally identical 11-line functions: - `handleSessionAgents` (lines 400–412) - `handleSessionCommands` (lines 414–426) - `handleSessionPermissions` (lines 442–454) - `handleSessionQuestions` (lines 456–468) ## Pattern Each calls `withSessionAdapter`, invokes the adapter method, nil-guards the result slice, and calls `writeJSON`. The only variation is the adapter method, the error message string, and the empty-slice type. ## Fix Could use Go generics (`func handleSessionCollection[T any](...)`) to collapse all four into a single generic handler. At minimum, the nil-guard pattern should be extracted. ## Effort Medium (full generic refactor); Low (nil-guard extraction only).
dries closed this issue 2026-07-04 19:53:55 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#42
No description provided.