Skip to content

Commit 770e157

Browse files
committed
renaming some funcs for visibility
1 parent 2dce571 commit 770e157

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

response/success.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ type contentHandler func(io.Reader, interface{}, *zap.SugaredLogger, string) err
2121

2222
// responseUnmarshallers maps MIME types to the corresponding contentHandler functions.
2323
var responseUnmarshallers = map[string]contentHandler{
24-
"application/json": unmarshalJSON,
25-
"application/xml": unmarshalXML,
26-
"text/xml": unmarshalXML,
24+
"application/json": handlerUnmarshalJSON,
25+
"application/xml": handlerUnmarshalXML,
26+
"text/xml": handlerUnmarshalXML,
2727
}
2828

2929
// HandleAPISuccessResponse reads the response body, logs the raw response details, and unmarshals the response based on the content type.
3030
func HandleAPISuccessResponse(resp *http.Response, out interface{}, sugar *zap.SugaredLogger) error {
3131
if resp.Request.Method == "DELETE" {
32-
return handleDeleteRequest(resp, sugar)
32+
return successfulDeleteRequest(resp, sugar)
3333
}
3434

3535
bodyBytes, err := io.ReadAll(resp.Body)
@@ -64,7 +64,7 @@ func HandleAPISuccessResponse(resp *http.Response, out interface{}, sugar *zap.S
6464
}
6565

6666
// handleDeleteRequest handles the special case for DELETE requests, where a successful response might not contain a body.
67-
func handleDeleteRequest(resp *http.Response, sugar *zap.SugaredLogger) error {
67+
func successfulDeleteRequest(resp *http.Response, sugar *zap.SugaredLogger) error {
6868
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
6969
sugar.Info("Successfully processed DELETE request", zap.String("URL", resp.Request.URL.String()), zap.Int("Status Code", resp.StatusCode))
7070
return nil
@@ -73,7 +73,7 @@ func handleDeleteRequest(resp *http.Response, sugar *zap.SugaredLogger) error {
7373
}
7474

7575
// unmarshalJSON unmarshals JSON content from an io.Reader into the provided output structure.
76-
func unmarshalJSON(reader io.Reader, out interface{}, sugar *zap.SugaredLogger, mimeType string) error {
76+
func handlerUnmarshalJSON(reader io.Reader, out interface{}, sugar *zap.SugaredLogger, mimeType string) error {
7777
decoder := json.NewDecoder(reader)
7878
if err := decoder.Decode(out); err != nil {
7979
sugar.Error("JSON Unmarshal error", zap.Error(err))
@@ -84,7 +84,7 @@ func unmarshalJSON(reader io.Reader, out interface{}, sugar *zap.SugaredLogger,
8484
}
8585

8686
// unmarshalXML unmarshals XML content from an io.Reader into the provided output structure.
87-
func unmarshalXML(reader io.Reader, out interface{}, sugar *zap.SugaredLogger, mimeType string) error {
87+
func handlerUnmarshalXML(reader io.Reader, out interface{}, sugar *zap.SugaredLogger, mimeType string) error {
8888
decoder := xml.NewDecoder(reader)
8989
if err := decoder.Decode(out); err != nil {
9090
sugar.Error("XML Unmarshal error", zap.Error(err))

response/t_success_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestHandleDeleteRequest_Success(t *testing.T) {
2222
},
2323
}
2424

25-
err := handleDeleteRequest(resp, nil)
25+
err := successfulDeleteRequest(resp, nil)
2626

2727
assert.NoError(t, err, "handleDeleteRequest should not return an error for successful DELETE requests")
2828
}
@@ -40,7 +40,7 @@ func TestHandleDeleteRequest_Failure(t *testing.T) {
4040
},
4141
}
4242

43-
err := handleDeleteRequest(resp, nil)
43+
err := successfulDeleteRequest(resp, nil)
4444

4545
assert.Error(t, err, "handleDeleteRequest should return an error for failed DELETE requests")
4646
}

0 commit comments

Comments
 (0)