If iterates on the error's causal chain and returns a predicate's return value the first time the predicate returns true. Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to If().
(err error, pred func(err error) (interface{}, bool))
| 149 | // package location or a different type, ensure that |
| 150 | // RegisterTypeMigration() was called prior to If(). |
| 151 | func If(err error, pred func(err error) (interface{}, bool)) (interface{}, bool) { |
| 152 | for c := err; c != nil; c = errbase.UnwrapOnce(c) { |
| 153 | if v, ok := pred(c); ok { |
| 154 | return v, ok |
| 155 | } |
| 156 | } |
| 157 | return nil, false |
| 158 | } |
| 159 | |
| 160 | // IsAny is like Is except that multiple references are compared. |
| 161 | // |