Skip to content

Commit

Permalink
简单修改
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyile committed Aug 25, 2024
1 parent adec07b commit c1b499a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 29 deletions.
8 changes: 8 additions & 0 deletions erkfc.go → erk_fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ func NewErkFm(erkFc func(format string, args ...interface{}) *errors.Error, msg
func NewErkFmx(erkFc func(format string, args ...interface{}) *errors.Error, msg string) func(erx error) *errors.Error {
return NewErkFm(erkFc, msg, "erx")
}

func As(erx error) (erk *errors.Error, ok bool) {
return erk, errors.As(erx, &erk)
}

func Is(erx error, target error) (ok bool) {
return errors.Is(erx, target)
}
59 changes: 59 additions & 0 deletions erk_fc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package erkkratos

import (
"testing"

"github.com/go-kratos/kratos/v2/errors"
"github.com/orzkratos/erkkratos/internal/errors_example"
"github.com/stretchr/testify/require"
"github.com/yyle88/erero"
)

func TestNewErkFsc(t *testing.T) {
erk := NewErkFsc(errors_example.ErrorServerDbError, "erk")(erero.New("wac"))
require.NotNil(t, erk)
require.True(t, errors_example.IsServerDbError(erk))
t.Log(erk)
}

func TestNewErkFmx(t *testing.T) {
erk := NewErkFmx(errors_example.ErrorServerDbError, "msg")(erero.New("wac"))
require.NotNil(t, erk)
require.True(t, errors_example.IsServerDbError(erk))
t.Log(erk)
}

func TestNewErkFmx2(t *testing.T) {
erk := NewErkFmx(errors_example.ErrorServerDbError, "msg")(erero.New("wac"))
require.NotNil(t, erk)
require.True(t, errors_example.IsServerDbError(erk))
t.Log(erk)

var err error
err = erk

var target *errors.Error
ok := errors.As(err, &target)
t.Log(ok)
t.Log(target)
}

func TestAs(t *testing.T) {
{
var erk = errors_example.ErrorServerDbError("wrong")
var erx error = erk
res, ok := As(erx)
require.True(t, ok)
t.Log(res)
require.NotNil(t, res)
}

{
var erk *errors.Error
var erx error = erk
res, ok := As(erx)
require.True(t, ok)
t.Log(res)
require.Nil(t, res)
}
}
23 changes: 0 additions & 23 deletions erkfc_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.6
require (
github.com/go-kratos/kratos/v2 v2.8.0
github.com/stretchr/testify v1.9.0
github.com/yyle88/erero v1.0.8
github.com/yyle88/erero v1.0.9
)

require (
Expand All @@ -18,7 +18,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240823204242-4ba0660f739c // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yyle88/erero v1.0.8 h1:UVXC5qGJ+UD7f2xsj75eVScLzVhiCKg7eXfP0yKNSqM=
github.com/yyle88/erero v1.0.8/go.mod h1:+qbuev+H/83Hr/zVTjkea2BxxUxAZWNeDVkoFu7ckgk=
github.com/yyle88/erero v1.0.9 h1:E6Llc9IsuSR151CPcE8Y97BapD+IgDR3yMwo+6CRnp4=
github.com/yyle88/erero v1.0.9/go.mod h1:+qbuev+H/83Hr/zVTjkea2BxxUxAZWNeDVkoFu7ckgk=
github.com/yyle88/mutexmap v1.0.3 h1:s5OqqR/oDW5ABhKZi25DLd4IE/KPPwlp6UyzqZayfXo=
github.com/yyle88/mutexmap v1.0.3/go.mod h1:xUqVmNE2/y4AMz5a8O3a4ik9Ua5xskEaLQ+ICnAAl8E=
github.com/yyle88/zaplog v0.0.7 h1:Kqwk+q4QatgS5Gyor2xGwSEQZ3U8Hai/ojkAz9BzOMY=
Expand All @@ -34,8 +34,8 @@ golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240823204242-4ba0660f739c h1:Kqjm4WpoWvwhMPcrAczoTyMySQmYa9Wy2iL6Con4zn8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240823204242-4ba0660f739c/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
Expand Down

0 comments on commit c1b499a

Please sign in to comment.