aboutsummaryrefslogtreecommitdiff
path: root/lib/errors/errors.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-08-06 20:02:18 +0700
committerShulhan <ms@kilabit.info>2021-08-06 20:02:18 +0700
commitdaa6c7dc238bcdd2026441d559ad7f130c5056e0 (patch)
tree1762b6e8bec0a3e89a3a5c376085fab494788365 /lib/errors/errors.go
parent5024d1c078f9eea37a7cbcb744b9b5ab7acfb127 (diff)
downloadpakakeh.go-daa6c7dc238bcdd2026441d559ad7f130c5056e0.tar.xz
lib/errrors: implement method As
The As method will set the target to instance of E only if only target is **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 35b74d1c..b9a5b9bd 100644
--- a/lib/errors/errors.go
+++ b/lib/errors/errors.go
@@ -7,6 +7,7 @@ package errors
import (
"net/http"
+ "reflect"
)
//
@@ -58,6 +59,19 @@ func (e *E) Error() string {
}
//
+// As set the target to e only if only target is **E.
+//
+func (e *E) As(target interface{}) bool {
+ _, ok := target.(**E)
+ if ok {
+ val := reflect.ValueOf(target)
+ val.Elem().Set(reflect.ValueOf(e))
+ return ok
+ }
+ return false
+}
+
+//
// Unwrap return the internal error.
//
func (e *E) Unwrap() error {