修复error输出错误问题
This commit is contained in:
18
int.go
18
int.go
@ -26,7 +26,7 @@ type Int int64
|
||||
// Date : 13:57 2023/5/5
|
||||
func (i Int) ToInt8() (int8, error) {
|
||||
if math.MaxInt8 < int64(i) || math.MinInt8 > int64(i) {
|
||||
return 0, fmt.Errorf("int8 value should between %v and %v ", math.MinInt8, math.MaxInt8)
|
||||
return 0, fmt.Errorf("int8 value should between %v and %v ", int8(math.MinInt8), int8(math.MaxInt8))
|
||||
}
|
||||
return int8(i), nil
|
||||
}
|
||||
@ -38,7 +38,7 @@ func (i Int) ToInt8() (int8, error) {
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt16() (int16, error) {
|
||||
if math.MaxInt16 < int64(i) || math.MinInt16 > int64(i) {
|
||||
return 0, fmt.Errorf("int16 value should between %v and %v ", math.MinInt16, math.MaxInt16)
|
||||
return 0, fmt.Errorf("int16 value should between %v and %v ", int16(math.MinInt16), int16(math.MaxInt16))
|
||||
}
|
||||
return int16(i), nil
|
||||
}
|
||||
@ -50,7 +50,7 @@ func (i Int) ToInt16() (int16, error) {
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt32() (int32, error) {
|
||||
if math.MaxInt32 < int64(i) || math.MinInt32 > int64(i) {
|
||||
return 0, fmt.Errorf("int32 value should between %v and %v ", math.MinInt32, math.MaxInt32)
|
||||
return 0, fmt.Errorf("int32 value should between %v and %v ", int32(math.MinInt32), int32(math.MaxInt32))
|
||||
}
|
||||
return int32(i), nil
|
||||
}
|
||||
@ -62,7 +62,7 @@ func (i Int) ToInt32() (int32, error) {
|
||||
// Date : 14:06 2023/5/5
|
||||
func (i Int) ToInt64() (int64, error) {
|
||||
if math.MaxInt64 < i || math.MinInt64 > i {
|
||||
return 0, fmt.Errorf("int64 value should between %v and %v ", math.MinInt64, math.MaxInt64)
|
||||
return 0, fmt.Errorf("int64 value should between %v and %v ", int64(math.MinInt64), int64(math.MaxInt64))
|
||||
}
|
||||
return int64(i), nil
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (i Int) ToInt64() (int64, error) {
|
||||
// Date : 14:07 2023/5/5
|
||||
func (i Int) ToInt() (int, error) {
|
||||
if math.MaxInt < i || math.MinInt > i {
|
||||
return 0, fmt.Errorf("int value should between %v and %v ", math.MinInt, math.MaxInt)
|
||||
return 0, fmt.Errorf("int value should between %v and %v ", int(math.MinInt), int(math.MaxInt))
|
||||
}
|
||||
return int(i), nil
|
||||
}
|
||||
@ -84,6 +84,10 @@ func (i Int) ToInt() (int, error) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:07 2023/5/5
|
||||
func (i Int) ToString() string {
|
||||
return fmt.Sprintf("%v", i)
|
||||
func (i Int) ToString() (string, error) {
|
||||
in64Val, err := i.ToInt64()
|
||||
if nil != err {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("%v", in64Val), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user