添加测试的方法

This commit is contained in:
Yun
2024-07-10 18:45:55 +08:00
parent f84d5b5d28
commit ca229263a5
2 changed files with 14 additions and 3 deletions
+12 -1
View File
@@ -23,10 +23,21 @@ func (e *LangError) Error() string {
return GetFormat(l, e.key, e.format) return GetFormat(l, e.key, e.format)
} }
func (e *LangError) Code() int { func (e *LangError) GetCode() int {
return GetCode(e.key) return GetCode(e.key)
} }
func (e *LangError) GetMsg() string {
return e.key
}
func (e *LangError) GetFormat() map[string]string {
if e.format == nil {
e.format = make(map[string]string)
}
return e.format
}
func NewErrorFormat(ctx context.Context, key string, format map[string]string) error { func NewErrorFormat(ctx context.Context, key string, format map[string]string) error {
return &LangError{ return &LangError{
ctx: ctx, ctx: ctx,
+2 -2
View File
@@ -37,7 +37,7 @@ func TestError(t *testing.T) {
t.Log(err.Error()) t.Log(err.Error())
val, ok := err.(*langx.LangError) val, ok := err.(*langx.LangError)
if ok { if ok {
t.Log(val.Code()) t.Log(val.GetCode())
} }
err = langx.NewErrorFormat(ctx, "username", map[string]string{ err = langx.NewErrorFormat(ctx, "username", map[string]string{
@@ -46,7 +46,7 @@ func TestError(t *testing.T) {
t.Log(err.Error()) t.Log(err.Error())
val, ok = err.(*langx.LangError) val, ok = err.(*langx.LangError)
if ok { if ok {
t.Log(val.Code()) t.Log(val.GetCode())
} }
} }