I have a set of constructs like this:
func LoginUser(w http.ResponseWriter, req *http.Request) {
// do some check here
if err != nil {
ReturnErrorResponse(w, errors.LoginError)
return
}
// do some check here
if err != nil {
ReturnErrorResponse(w, errors.BannedUserError)
return
}
//success
}
I wonder if it's possible to get rid of these return
s and somehow embed them into the ReturnErrorResponse
function?
So, if an error happens, I return a JSONified response with error code and make a naked return.