Skip to content

Conversation

metachris
Copy link
Contributor

πŸ“ Summary

Make API calls return a JSON response, also JSON errors.

PR also fixes examples in the README.


βœ… I have run these commands

  • make lint
  • make test
  • go mod tidy

@metachris metachris requested review from MoeMahhouk and bakhtin March 18, 2025 17:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR standardizes API responses to use JSON format throughout the system API, replacing simple HTTP status codes with structured JSON responses for both success and error cases.

  • Implements consistent JSON response format for all API endpoints
  • Introduces structured error responses with status codes and messages
  • Adds helper methods for standardized JSON response handling

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
systemapi/server.go Adds JSON response helper methods and converts all endpoints to return structured JSON responses
systemapi/middleware.go Updates basic auth middleware to return JSON error responses
systemapi/constants.go Defines HTTP header and media type constants for consistent usage
systemapi-config.toml Corrects filename reference in configuration comments
README.md Updates example commands to use HTTPS and corrects configuration references

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +54 to +57
resp := httpErrorResp{
Code: http.StatusUnauthorized,
Message: "Unauthorized",
}
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

The httpErrorResp struct is referenced here but not defined in this file. This creates a dependency on server.go that should be avoided. Consider moving the struct to a shared location like constants.go or creating a dedicated types file.

Copilot uses AI. Check for mistakes.

s.respondOKJSON(w, map[string]string{
"message": "File uploaded successfully",
"file": filename,
"size_bytes": fmt.Sprint(len(content)), //nolint:perfsprint
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

The nolint comment suggests awareness of a performance issue with fmt.Sprint. Consider using strconv.Itoa(len(content)) instead, which is more efficient for integer-to-string conversion.

Copilot uses AI. Check for mistakes.

@metachris metachris merged commit 4b74015 into main Sep 18, 2025
2 checks passed
@metachris metachris deleted the json-resp branch September 18, 2025 17:18
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