Skip to content

Commit

Permalink
Merge pull request #29 from moul/dev/moul/checkerr
Browse files Browse the repository at this point in the history
feat: add CheckErr
  • Loading branch information
moul authored Nov 12, 2020
2 parents 82a73b6 + 372121f commit a1b8595
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ func CombineFuncs(left func(), right ...func()) func() {
}
}
}

// CheckErr panics if the passed error is not nil.
func CheckErr(err error) {
if err != nil {
panic(err)
}
}
6 changes: 6 additions & 0 deletions pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package u_test

import (
"fmt"
"net/http"

"moul.io/u"
)
Expand All @@ -13,3 +14,8 @@ func ExampleCombineFuncs() {
cleanup()
// Output: CAB
}

func ExampleCheckErr() {
_, err := http.Get("http://foo.bar")
u.CheckErr(err) // panic
}

0 comments on commit a1b8595

Please sign in to comment.