Add function for avoiding 'if err != nil' constructs everywhere.
This commit is contained in:
parent
424e53c78d
commit
e93e4cc115
1 changed files with 7 additions and 0 deletions
|
|
@ -94,6 +94,13 @@ func (e *errorWithStatus) Error() string {
|
|||
func newError(mesg_format string, args ...interface{}) *errorWithStatus {
|
||||
return newErrorStatus(http.StatusInternalServerError, mesg_format, args...)
|
||||
}
|
||||
func newErrorMaybe(mesg_format string, err error, args ...interface{}) *errorWithStatus {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
allArgs := append([]interface{}{err}, args...)
|
||||
return newErrorStatus(http.StatusInternalServerError, mesg_format, allArgs...)
|
||||
}
|
||||
func newErrorStatus(status int, mesg_format string, args ...interface{}) *errorWithStatus {
|
||||
w := fmt.Errorf(mesg_format, args...)
|
||||
return &errorWithStatus{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue