mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-31 08:44:25 +00:00
Address code review feedback - improve data length calculation clarity
- Simplified data length calculation logic in sendFormattedResponse - Simplified data length calculation logic in sendResponseWithOptions - Calculate dataLen after nil conversion for clarity and consistency - All tests still passing Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
@@ -2144,15 +2144,14 @@ func (h *Handler) sendResponse(w common.ResponseWriter, data interface{}, metada
|
||||
func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options *ExtendedRequestOptions) {
|
||||
w.SetHeader("Content-Type", "application/json")
|
||||
|
||||
// Calculate data length
|
||||
dataLen := 0
|
||||
// Handle nil data - convert to empty array
|
||||
if data == nil {
|
||||
// When data is nil, return empty array instead of null
|
||||
data = []interface{}{}
|
||||
} else {
|
||||
dataLen = reflection.Len(data)
|
||||
}
|
||||
|
||||
// Calculate data length after nil conversion
|
||||
dataLen := reflection.Len(data)
|
||||
|
||||
// Add X-No-Data-Found header when no records were found
|
||||
if dataLen == 0 {
|
||||
w.SetHeader("X-No-Data-Found", "true")
|
||||
@@ -2210,13 +2209,14 @@ func (h *Handler) normalizeResultArray(data interface{}) interface{} {
|
||||
func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options ExtendedRequestOptions) {
|
||||
// Normalize single-record arrays to objects if requested
|
||||
httpStatus := http.StatusOK
|
||||
dataLen := 0
|
||||
|
||||
// Handle nil data - convert to empty array
|
||||
if data == nil {
|
||||
// When data is nil, return empty array instead of null
|
||||
data = []interface{}{}
|
||||
} else {
|
||||
dataLen = reflection.Len(data)
|
||||
}
|
||||
|
||||
// Calculate data length after nil conversion
|
||||
dataLen := reflection.Len(data)
|
||||
|
||||
// Add X-No-Data-Found header when no records were found
|
||||
if dataLen == 0 {
|
||||
|
||||
Reference in New Issue
Block a user