mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-12 02:27:28 +08:00
优化自定义错误类型
This commit is contained in:
@@ -13,16 +13,11 @@ type FuncRpcClient func(nodeid int,serviceMethod string) ([]*Client,error)
|
|||||||
type FuncRpcServer func() (*Server)
|
type FuncRpcServer func() (*Server)
|
||||||
var NilError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())
|
var NilError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())
|
||||||
|
|
||||||
type RpcError struct {
|
type RpcError string
|
||||||
Err string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *RpcError) Error() string {
|
|
||||||
return slf.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRpcError(e string) *RpcError {
|
func (e RpcError) Error() string {
|
||||||
return &RpcError{Err:e}
|
return string(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertError(e error) *RpcError{
|
func ConvertError(e error) *RpcError{
|
||||||
@@ -30,11 +25,13 @@ func ConvertError(e error) *RpcError{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RpcError{Err:e.Error()}
|
rpcErr := RpcError(e.Error())
|
||||||
|
return &rpcErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func Errorf(format string, a ...interface{}) *RpcError {
|
func Errorf(format string, a ...interface{}) *RpcError {
|
||||||
return NewRpcError(fmt.Sprintf(format,a...))
|
rpcErr := RpcError(fmt.Sprintf(format,a...))
|
||||||
|
return &rpcErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user