From 9636e6bcf08864bb7a71dc5bdc865eb07966b2fa Mon Sep 17 00:00:00 2001 From: Vincent <532000663@qq.com> Date: Tue, 8 Sep 2020 23:22:12 +0800 Subject: [PATCH] =?UTF-8?q?validate=20=E4=BD=BF=E7=94=A8=20grpc=20?= =?UTF-8?q?=E6=A0=87=E5=87=86=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=20(#627)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/net/rpc/warden/validate.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/net/rpc/warden/validate.go b/pkg/net/rpc/warden/validate.go index ddd715ca6..94d3d212e 100644 --- a/pkg/net/rpc/warden/validate.go +++ b/pkg/net/rpc/warden/validate.go @@ -2,8 +2,8 @@ package warden import ( "context" - - "github.com/go-kratos/kratos/pkg/ecode" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "google.golang.org/grpc" "gopkg.in/go-playground/validator.v9" @@ -15,7 +15,7 @@ var validate = validator.New() func (s *Server) validate() grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, args *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { if err = validate.Struct(req); err != nil { - err = ecode.Error(ecode.RequestErr, err.Error()) + err = status.Error(codes.InvalidArgument, err.Error()) return } resp, err = handler(ctx, req) @@ -30,7 +30,7 @@ func (s *Server) RegisterValidation(key string, fn validator.Func) error { return validate.RegisterValidation(key, fn) } -//GetValidate return the default validate +// GetValidate return the default validate func (s *Server) GetValidate() *validator.Validate { return validate }