Skip to content

Fix #67: Add WriteJSON helper to httpserver package#68

Merged
mishankov merged 2 commits intomainfrom
issue-67-writejson-helper
Mar 3, 2026
Merged

Fix #67: Add WriteJSON helper to httpserver package#68
mishankov merged 2 commits intomainfrom
issue-67-writejson-helper

Conversation

@mishankov
Copy link
Copy Markdown
Member

Summary

Closes #67

Adds a WriteJSON helper function to the httpserver package for writing JSON HTTP responses.

Changes

  • Added WriteJSON(ctx context.Context, w http.ResponseWriter, statusCode int, data any) error function
  • Function sets Content-Type: application/json header
  • Writes the specified HTTP status code
  • Encodes the data as JSON to the response writer
  • Logs encoding errors via log.ErrorContext
  • Returns wrapped error on encoding failures

Testing

  • Added comprehensive tests in response_test.go covering:
    • JSON response with custom status code
    • Struct encoding
    • Error handling on unencodable data
  • All tests pass: go test ./httpserver/...
  • Linting clean: golangci-lint run reports 0 issues

Code Review

No P0/P1 blockers found. Implementation follows existing patterns in the auth handlers.

@mishankov mishankov force-pushed the issue-67-writejson-helper branch from a43d063 to 1ef2769 Compare March 2, 2026 13:26
Replace manual JSON encoding with httpserver.WriteJSON() helper:

- application/healthcheck.go: simplify health response

- auth/handler_delete.go: fix error log message (was "decode")

- auth/handler_get.go: remove redundant Content-Type header

Reduces code duplication and ensures consistent response handling.
@mishankov mishankov merged commit 378840f into main Mar 3, 2026
6 checks passed
@mishankov mishankov deleted the issue-67-writejson-helper branch March 3, 2026 04:48
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.

Helpers in httpserver package

1 participant