From 8d3bd7cade2a3ebd73253c1ae023e2e72ea9aa35 Mon Sep 17 00:00:00 2001 From: Yun Date: Wed, 31 Jul 2024 16:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- error.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/error.go b/error.go index e6d2f01..b9aa56e 100644 --- a/error.go +++ b/error.go @@ -5,12 +5,12 @@ import ( ) type LangError interface { - NewError(ctx context.Context, key string) error - NewErrorFormat(ctx context.Context, key string, format map[string]string) error - Error() string - GetCode() int - GetMsg() string - GetFormat() map[string]string + NewError(ctx context.Context, key string) error // New错误 + NewErrorFormat(ctx context.Context, key string, format map[string]string) error // New错误 + Error() string // 实现error接口&获取翻译后的错误信息 + GetCode() int // 获取翻译后的Code + GetKey() string // 获取原Key值 + GetFormat() map[string]string // 获取附加数据 } type langError struct { @@ -21,8 +21,6 @@ type langError struct { type errorConst string -const errorLang errorConst = "errorLang" - func (e *langError) Error() string { errLang := e.ctx.Value(errorLang) l := "" @@ -36,7 +34,7 @@ func (e *langError) GetCode() int { return GetCode(e.key) } -func (e *langError) GetMsg() string { +func (e *langError) GetKey() string { return e.key } @@ -62,6 +60,8 @@ func NewError(ctx context.Context, key string) error { } } +const errorLang errorConst = "errorLang" + func SetCtxLang(ctx context.Context, lang string) context.Context { return context.WithValue(ctx, errorLang, lang) }