DUP-GO-5: 6 POST-then-204 session handlers share identical boilerplate #39

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

Summary

Six mutating session handlers in internal/server/handlers_sessions.go (lines 523–675) are structurally identical:

  • handleSessionMessage
  • handleSessionCommand
  • handleSessionShell
  • handleSessionRename
  • handleSessionAbort
  • handleSessionCompact

Pattern

Each handler: reads + unmarshals request → validates fields → withSessionAdapterwritePlatformError on error → w.WriteHeader(http.StatusNoContent) on success.

~150 lines of near-identical boilerplate.

Fix

Extract the withSessionAdapter + writePlatformError + 204 epilogue into a shared dispatch helper. Request struct definitions and field-level validation necessarily remain per-handler.

Effort

Medium.

## Summary Six mutating session handlers in `internal/server/handlers_sessions.go` (lines 523–675) are structurally identical: - `handleSessionMessage` - `handleSessionCommand` - `handleSessionShell` - `handleSessionRename` - `handleSessionAbort` - `handleSessionCompact` ## Pattern Each handler: reads + unmarshals request → validates fields → `withSessionAdapter` → `writePlatformError` on error → `w.WriteHeader(http.StatusNoContent)` on success. ~150 lines of near-identical boilerplate. ## Fix Extract the `withSessionAdapter` + `writePlatformError` + 204 epilogue into a shared dispatch helper. Request struct definitions and field-level validation necessarily remain per-handler. ## Effort Medium.
dries closed this issue 2026-07-11 11:23:17 +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#39
No description provided.