From 5d95b333f189151f3c90e19db742926e55bbd19c Mon Sep 17 00:00:00 2001 From: wei cheng Date: Tue, 21 May 2019 13:37:00 +0800 Subject: [PATCH 1/2] remove pb ecode --- pkg/{ecode => net/rpc/warden/internal}/pb/ecode.go | 0 pkg/{ecode => net/rpc/warden/internal}/pb/ecode.pb.go | 0 pkg/{ecode => net/rpc/warden/internal}/pb/ecode.proto | 0 pkg/net/rpc/warden/internal/status/status.go | 2 +- pkg/net/rpc/warden/internal/status/status_test.go | 2 +- 5 files changed, 2 insertions(+), 2 deletions(-) rename pkg/{ecode => net/rpc/warden/internal}/pb/ecode.go (100%) rename pkg/{ecode => net/rpc/warden/internal}/pb/ecode.pb.go (100%) rename pkg/{ecode => net/rpc/warden/internal}/pb/ecode.proto (100%) diff --git a/pkg/ecode/pb/ecode.go b/pkg/net/rpc/warden/internal/pb/ecode.go similarity index 100% rename from pkg/ecode/pb/ecode.go rename to pkg/net/rpc/warden/internal/pb/ecode.go diff --git a/pkg/ecode/pb/ecode.pb.go b/pkg/net/rpc/warden/internal/pb/ecode.pb.go similarity index 100% rename from pkg/ecode/pb/ecode.pb.go rename to pkg/net/rpc/warden/internal/pb/ecode.pb.go diff --git a/pkg/ecode/pb/ecode.proto b/pkg/net/rpc/warden/internal/pb/ecode.proto similarity index 100% rename from pkg/ecode/pb/ecode.proto rename to pkg/net/rpc/warden/internal/pb/ecode.proto diff --git a/pkg/net/rpc/warden/internal/status/status.go b/pkg/net/rpc/warden/internal/status/status.go index 7696a13f7..a54eaa437 100644 --- a/pkg/net/rpc/warden/internal/status/status.go +++ b/pkg/net/rpc/warden/internal/status/status.go @@ -11,7 +11,7 @@ import ( "google.golang.org/grpc/status" "github.com/bilibili/kratos/pkg/ecode" - "github.com/bilibili/kratos/pkg/ecode/pb" + "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/pb" ) // togRPCCode convert ecode.Codo to gRPC code diff --git a/pkg/net/rpc/warden/internal/status/status_test.go b/pkg/net/rpc/warden/internal/status/status_test.go index 48da6c42f..43013e9b4 100644 --- a/pkg/net/rpc/warden/internal/status/status_test.go +++ b/pkg/net/rpc/warden/internal/status/status_test.go @@ -15,7 +15,7 @@ import ( "google.golang.org/grpc/status" "github.com/bilibili/kratos/pkg/ecode" - "github.com/bilibili/kratos/pkg/ecode/pb" + "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/pb" ) func TestCodeConvert(t *testing.T) { From 92ac678e8afb47ca4dedbf9c3d3121e90c144bcc Mon Sep 17 00:00:00 2001 From: wei cheng Date: Tue, 21 May 2019 13:53:21 +0800 Subject: [PATCH 2/2] fix example --- pkg/net/rpc/warden/internal/examples/server/main.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/net/rpc/warden/internal/examples/server/main.go b/pkg/net/rpc/warden/internal/examples/server/main.go index 738afdb51..667e1819b 100644 --- a/pkg/net/rpc/warden/internal/examples/server/main.go +++ b/pkg/net/rpc/warden/internal/examples/server/main.go @@ -10,13 +10,11 @@ import ( "time" "github.com/bilibili/kratos/pkg/ecode" - epb "github.com/bilibili/kratos/pkg/ecode/pb" "github.com/bilibili/kratos/pkg/log" "github.com/bilibili/kratos/pkg/net/rpc/warden" pb "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/proto/testproto" xtime "github.com/bilibili/kratos/pkg/time" - "github.com/golang/protobuf/ptypes" "google.golang.org/grpc" ) @@ -26,9 +24,7 @@ type helloServer struct { func (s *helloServer) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { if in.Name == "err_detail_test" { - any, _ := ptypes.MarshalAny(&pb.HelloReply{Success: true, Message: "this is test detail"}) - err := epb.From(ecode.AccessDenied) - err.ErrDetail = any + err, _ := ecode.Error(ecode.AccessDenied, "AccessDenied").WithDetails(&pb.HelloReply{Success: true, Message: "this is test detail"}) return nil, err } return &pb.HelloReply{Message: fmt.Sprintf("hello %s from %s", in.Name, s.addr)}, nil