From 76fabd44bb57016fd5a6132bdc24d399a7ec1e9b Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 22 Dec 2018 19:50:52 +0100 Subject: [PATCH] add OptDo wrapper --- goutil.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/goutil.go b/goutil.go index c3a5868..8ce4477 100644 --- a/goutil.go +++ b/goutil.go @@ -96,6 +96,14 @@ func AskFor(question string) (string, error) { } } +func OptDo(err error, f func() error) error { + if err == nil { + return f() + } else { + return err + } +} + func IntMin(x, y int) int { if x < y { return x