aboutsummaryrefslogtreecommitdiff
path: root/lib/errors/errors.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-11 12:35:38 +0700
committerShulhan <ms@kilabit.info>2023-09-11 12:35:38 +0700
commita54854d80e96a94156d702379032a25e85a67914 (patch)
tree2e3cd23901d3a640117a7b510e0a660ce3af72e7 /lib/errors/errors.go
parentef1b1a8992cc71cbc52dbf68218c2feffb0c3c94 (diff)
downloadpakakeh.go-a54854d80e96a94156d702379032a25e85a67914.tar.xz
lib/errors: implement method Is
The Is method will return true if the target error is instance of *E and the value of field Code and Name match with values in e.
Diffstat (limited to 'lib/errors/errors.go')
-rw-r--r--lib/errors/errors.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/errors/errors.go b/lib/errors/errors.go
index 342dbef0..ae339241 100644
--- a/lib/errors/errors.go
+++ b/lib/errors/errors.go
@@ -61,6 +61,20 @@ func (e *E) As(target interface{}) bool {
return false
}
+// Is return true if the target error is instance of *E and the value of
+// field Code and Name match with values in e.
+func (e *E) Is(target error) bool {
+ var (
+ etarget *E
+ ok bool
+ )
+ etarget, ok = target.(*E)
+ if !ok {
+ return false
+ }
+ return e.Code == etarget.Code && e.Name == etarget.Name
+}
+
// Unwrap return the internal error.
func (e *E) Unwrap() error {
return e.err