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