api: DRY code and add new test

This commit makes code cleaner and reduces the repetitions in the code
base. Specifically, it reduces the clutter in setObjectHeaders. It also
merges encodeSuccessResponse and encodeErrorResponse together because
they served no purpose differently. Finally, it adds a simple test for
generateRequestID.
This commit is contained in:
Brendan Ashworth
2016-03-06 12:16:22 -08:00
parent e883583804
commit adf74ffdb0
5 changed files with 63 additions and 38 deletions
+1 -1
View File
@@ -436,7 +436,7 @@ func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int,
error := getErrorCode(errorType)
// generate error response
errorResponse := getErrorResponse(error, resource)
encodedErrorResponse := encodeErrorResponse(errorResponse)
encodedErrorResponse := encodeResponse(errorResponse)
// set common headers
setCommonHeaders(w)
// write Header