调整方法

This commit is contained in:
Yun
2025-10-26 20:58:12 +08:00
parent d1bda7e355
commit 8eaa8a6933
5 changed files with 14 additions and 11 deletions
+6 -4
View File
@@ -3,6 +3,8 @@ package errorx_test
import (
"context"
"testing"
"github.com/yuninks/errorx"
"github.com/yuninks/langx"
)
@@ -31,19 +33,19 @@ func TestError(t *testing.T) {
"username": "Hello #name#", // 有占位符
})
err = langx.NewError(ctx, "error")
err = errorx.NewError(ctx, "error")
// fmt.Printf("err: %v\n", err)
t.Log(err.Error())
val, ok := err.(langx.LangError)
val, ok := err.(errorx.ErrorInterface)
if ok {
t.Log(val.GetCode())
}
err = langx.NewErrorf(ctx, "username", map[string]string{
err = errorx.NewErrorf(ctx, "username", map[string]string{
"name": "yuninks",
})
t.Log(err.Error())
val, ok = err.(langx.LangError)
val, ok = err.(errorx.ErrorInterface)
if ok {
t.Log(val.GetCode())
+2 -2
View File
@@ -9,7 +9,7 @@ import (
// 定义错误常量
type ErrorLanguage struct {
langx.LangError
ErrorInterface
}
// 生成错误常量
@@ -17,7 +17,7 @@ func NewLanguage(uniKey string, code int, defaultValue string) ErrorLanguage {
langx.AppendCode(map[string]int{uniKey: code})
langx.AppendTrans(langx.GetDefaultLang(), map[string]string{uniKey: defaultValue})
l := langx.NewStruct(context.Background(), uniKey, nil)
l := NewStruct(context.Background(), uniKey, nil)
return ErrorLanguage{l}
}
+3 -2
View File
@@ -3,6 +3,7 @@ package main
import (
"context"
"github.com/yuninks/errorx"
"github.com/yuninks/langx"
)
@@ -33,11 +34,11 @@ func (l Language) String() string {
}
func (l Language) Error() error {
return langx.NewError(context.Background(), l.String())
return errorx.NewError(context.Background(), l.String())
}
func (l Language) Errorf(format map[string]string) error {
return langx.NewErrorf(context.Background(), l.String(), format)
return errorx.NewErrorf(context.Background(), l.String(), format)
}
var (
+1 -1
View File
@@ -2,4 +2,4 @@ module github.com/yuninks/errorx
go 1.22.4
require github.com/yuninks/langx v0.0.6
require github.com/yuninks/langx v0.0.7
+2 -2
View File
@@ -1,2 +1,2 @@
github.com/yuninks/langx v0.0.6 h1:+gUttpogalaUaKlqm2AsY5sNnSpoVj58jqEM1oFKWTk=
github.com/yuninks/langx v0.0.6/go.mod h1:nAylzjNIjCThhEQSJsIKP8Vhja0aJlcyig+NsNPZLSk=
github.com/yuninks/langx v0.0.7 h1:QUt27h/FjnT7//759GoM/+p4ew+HBr10ZN/fkqeQfyA=
github.com/yuninks/langx v0.0.7/go.mod h1:nAylzjNIjCThhEQSJsIKP8Vhja0aJlcyig+NsNPZLSk=