✨ Refactor ResponseHelper and add ResponderHandler
- Modified ResponseHelper.Body signature to return an io.Reader and an error. - Updated ResponseHandler.ServeHTTP to handle errors from ResponseHelper.Body. - Implemented JSONResponse and JSONResponseWithStatus functions for easier JSON responses. - Added comprehensive unit tests for JSON response handling, including error scenarios. - Extended Helper.ResponderHandler with a new test case to ensure proper error handling and response generation. - Resolved linting issues related to dynamic error definition and function length in tests.
This commit is contained in:
parent
a136616088
commit
1c16a893d6
5 changed files with 270 additions and 1 deletions
|
|
@ -34,3 +34,9 @@ func (help *Helper) HandlerFunc(hnd HandlerFunc) http.Handler {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
// ResponderHandler returns an [http.Handler] for the provided [ResponderHandler].
|
||||
// If hnd returns an error, an appropriate error response is written using the ErrorHandler.
|
||||
func (help *Helper) ResponderHandler(hnd ResponseHandler) http.Handler {
|
||||
return help.Handler(hnd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue