mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
feat(errors/gerror): add As support (#4002)
This commit is contained in:
@ -98,6 +98,23 @@ func Is(err, target error) bool {
|
||||
return errors.Is(err, target)
|
||||
}
|
||||
|
||||
// As finds the first error in err's chain that matches target, and if so, sets
|
||||
// target to that error value and returns true.
|
||||
//
|
||||
// The chain consists of err itself followed by the sequence of errors obtained by
|
||||
// repeatedly calling Unwrap.
|
||||
//
|
||||
// An error matches target if the error's concrete value is assignable to the value
|
||||
// pointed to by target, or if the error has a method As(interface{}) bool such that
|
||||
// As(target) returns true. In the latter case, the As method is responsible for
|
||||
// setting target.
|
||||
//
|
||||
// As will panic if target is not a non-nil pointer to either a type that implements
|
||||
// error, or to any interface type. As returns false if err is nil.
|
||||
func As(err error, target any) bool {
|
||||
return errors.As(err, target)
|
||||
}
|
||||
|
||||
// HasError performs as Is.
|
||||
// This function is designed and implemented early before errors.Is of go stdlib.
|
||||
// Deprecated: use Is instead.
|
||||
|
||||
Reference in New Issue
Block a user