From 8c8c730a3be51b04032150ebd616e053983d59eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 28 Sep 2023 00:40:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E5=88=B6?= =?UTF-8?q?=E5=AE=9A=E9=94=99=E8=AF=AF=E7=A0=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstrace.go | 2 ++ exception.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/abstrace.go b/abstrace.go index e8b2ffe..fb67c37 100644 --- a/abstrace.go +++ b/abstrace.go @@ -29,4 +29,6 @@ type IException interface { GetHttpCode() int // ToError 转换为内置error类型 ToError() error + // IsCode 是否为指定code + IsCode(code interface{}) bool } diff --git a/exception.go b/exception.go index f63ddea..d868655 100644 --- a/exception.go +++ b/exception.go @@ -59,6 +59,15 @@ func (e *Exception) ToError() error { return errors.New(e.Error()) } +// IsCode 判断是否为指定错误码 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 00:39 2023/9/28 +func (e *Exception) IsCode(inputCode interface{}) bool { + return fmt.Sprintf("%v", inputCode) == fmt.Sprintf("%v", e.GetCode()) +} + // NewWithCode 仅使用错误码实例化异常 // // Author : go_developer@163.com<白茶清欢>