DUP-GO-2: identical request-validation preamble in 3 state mutation handlers #46

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

Summary

Three handlers in internal/server/handlers_state.go share an identical ~10-line validation preamble:

  • handleSeenSession (lines 33–61)
  • handleArchiveSession (lines 63–98)
  • handlePinSession (lines 100–130)

Duplicated block

if !readAndUnmarshal(w, r, maxRequestBody, &req) { return }
if !validateID(req.SessionID) {
    http.Error(w, "invalid session ID", http.StatusBadRequest)
    return
}
platform, ok := s.resolvePlatformIDForState(w, r, req.SessionID, req.Platform)
if !ok { return }

All three also return writeJSON(w, map[string]bool{"ok": true}) on success.

Fix

Extract the preamble into a shared helper that returns the platform string.

Effort

Trivial.

## Summary Three handlers in `internal/server/handlers_state.go` share an identical ~10-line validation preamble: - `handleSeenSession` (lines 33–61) - `handleArchiveSession` (lines 63–98) - `handlePinSession` (lines 100–130) ## Duplicated block ```go if !readAndUnmarshal(w, r, maxRequestBody, &req) { return } if !validateID(req.SessionID) { http.Error(w, "invalid session ID", http.StatusBadRequest) return } platform, ok := s.resolvePlatformIDForState(w, r, req.SessionID, req.Platform) if !ok { return } ``` All three also return `writeJSON(w, map[string]bool{"ok": true})` on success. ## Fix Extract the preamble into a shared helper that returns the platform string. ## Effort Trivial.
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#46
No description provided.