github.com/tencent/goom@v1.0.1/erro/return_not_match.go (about) 1 package erro 2 3 import ( 4 "reflect" 5 "strconv" 6 ) 7 8 // ReturnsNotMatch 返回参数不匹配异常 9 type ReturnsNotMatch struct { 10 funcDef interface{} 11 argLen int 12 expectLen int 13 } 14 15 // Error 返回错误字符串 16 func (i *ReturnsNotMatch) Error() string { 17 if i.funcDef != nil { 18 return "returns lenth not match of func " + reflect.ValueOf(i.funcDef).String() + 19 ": " + strconv.Itoa(i.argLen) + ", expect: " + strconv.Itoa(i.expectLen) 20 } 21 return "returns lenth not match: " + strconv.Itoa(i.argLen) + ", expect: " + strconv.Itoa(i.expectLen) 22 } 23 24 // NewReturnsNotMatchError 创建参数异常 25 // funcDef 函数定义 26 // argLen 参数长度 27 // expectLen 期望长度 28 func NewReturnsNotMatchError(funcDef interface{}, argLen int, expectLen int) error { 29 return &ArgsNotMatch{funcDef: funcDef, argLen: argLen, expectLen: expectLen} 30 }