mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-09 04:54:25 +00:00
Fix formatting issues with gofmt
- Removed trailing whitespace - Fixed tab/space alignment in struct definitions - All tests still passing Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
@@ -14,9 +14,9 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) {
|
|||||||
handler := &Handler{}
|
handler := &Handler{}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input interface{}
|
input interface{}
|
||||||
shouldBeEmptyArr bool
|
shouldBeEmptyArr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "nil should return empty array",
|
name: "nil should return empty array",
|
||||||
@@ -57,7 +57,7 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) {
|
|||||||
if len(emptyArr) != 0 {
|
if len(emptyArr) != 0 {
|
||||||
t.Errorf("Expected empty array with length 0, got length %d", len(emptyArr))
|
t.Errorf("Expected empty array with length 0, got length %d", len(emptyArr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify it serializes to [] and not null
|
// Verify it serializes to [] and not null
|
||||||
jsonBytes, err := json.Marshal(result)
|
jsonBytes, err := json.Marshal(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2143,22 +2143,22 @@ func (h *Handler) sendResponse(w common.ResponseWriter, data interface{}, metada
|
|||||||
// sendResponseWithOptions sends a response with optional formatting
|
// sendResponseWithOptions sends a response with optional formatting
|
||||||
func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options *ExtendedRequestOptions) {
|
func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options *ExtendedRequestOptions) {
|
||||||
w.SetHeader("Content-Type", "application/json")
|
w.SetHeader("Content-Type", "application/json")
|
||||||
|
|
||||||
// Handle nil data - convert to empty array
|
// Handle nil data - convert to empty array
|
||||||
if data == nil {
|
if data == nil {
|
||||||
data = []interface{}{}
|
data = []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate data length after nil conversion
|
// Calculate data length after nil conversion
|
||||||
dataLen := reflection.Len(data)
|
dataLen := reflection.Len(data)
|
||||||
|
|
||||||
// Add X-No-Data-Found header when no records were found
|
// Add X-No-Data-Found header when no records were found
|
||||||
if dataLen == 0 {
|
if dataLen == 0 {
|
||||||
w.SetHeader("X-No-Data-Found", "true")
|
w.SetHeader("X-No-Data-Found", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
// Normalize single-record arrays to objects if requested
|
// Normalize single-record arrays to objects if requested
|
||||||
if options != nil && options.SingleRecordAsObject {
|
if options != nil && options.SingleRecordAsObject {
|
||||||
data = h.normalizeResultArray(data)
|
data = h.normalizeResultArray(data)
|
||||||
@@ -2209,12 +2209,12 @@ func (h *Handler) normalizeResultArray(data interface{}) interface{} {
|
|||||||
func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options ExtendedRequestOptions) {
|
func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options ExtendedRequestOptions) {
|
||||||
// Normalize single-record arrays to objects if requested
|
// Normalize single-record arrays to objects if requested
|
||||||
httpStatus := http.StatusOK
|
httpStatus := http.StatusOK
|
||||||
|
|
||||||
// Handle nil data - convert to empty array
|
// Handle nil data - convert to empty array
|
||||||
if data == nil {
|
if data == nil {
|
||||||
data = []interface{}{}
|
data = []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate data length after nil conversion
|
// Calculate data length after nil conversion
|
||||||
// Note: This is done BEFORE normalization because X-No-Data-Found indicates
|
// Note: This is done BEFORE normalization because X-No-Data-Found indicates
|
||||||
// whether data was found in the database, not the final response format
|
// whether data was found in the database, not the final response format
|
||||||
|
|||||||
Reference in New Issue
Block a user