github.com/tencent/goom@v1.0.1/erro/arg_not_match.go (about)

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