From 4e6e7c0c9522042f77648674987b8e2d4a6f55f5 Mon Sep 17 00:00:00 2001 From: duanhf2012 Date: Wed, 1 Apr 2020 13:52:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/rpchandler.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/rpc/rpchandler.go b/rpc/rpchandler.go index 828a8a2..4f77825 100644 --- a/rpc/rpchandler.go +++ b/rpc/rpchandler.go @@ -13,16 +13,11 @@ type FuncRpcClient func(nodeid int,serviceMethod string) ([]*Client,error) type FuncRpcServer func() (*Server) var NilError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem()) -type RpcError struct { - Err string -} +type RpcError string -func (slf *RpcError) Error() string { - return slf.Err -} -func NewRpcError(e string) *RpcError { - return &RpcError{Err:e} +func (e RpcError) Error() string { + return string(e) } func ConvertError(e error) *RpcError{ @@ -30,11 +25,13 @@ func ConvertError(e error) *RpcError{ return nil } - return &RpcError{Err:e.Error()} + rpcErr := RpcError(e.Error()) + return &rpcErr } func Errorf(format string, a ...interface{}) *RpcError { - return NewRpcError(fmt.Sprintf(format,a...)) + rpcErr := RpcError(fmt.Sprintf(format,a...)) + return &rpcErr }