into.go 261 B

1234567891011
  1. //go:build go1.18
  2. package errors
  3. // Into finds the first error in err's chain that matches target type T, and if so, returns it.
  4. //
  5. // Into is type-safe alternative to As.
  6. func Into[T error](err error) (val T, ok bool) {
  7. ok = As(err, &val)
  8. return val, ok
  9. }