package e type ApiError struct { ErrMsg string Code int } func (err *ApiError) Error() string { return err.ErrMsg } /** 参数1 对应 ApiError ErrMsg 参数2 对应 ApiError Code 默认1001 */ func NewApiError(opts ...interface{}) * ApiError{ var ErrMsg string; Code:=1001; for num,opt:=range opts{ if(num>1){ break; } switch num { case 0: ErrMsg=opt.(string) case 1: Code=opt.(int) break } } return &ApiError{ ErrMsg: ErrMsg,Code:Code} }