From d1af45af10c9ab473dee654ca51ec35e1dc944be Mon Sep 17 00:00:00 2001 From: libin Date: Wed, 3 Apr 2024 10:29:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20err=20code=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=E5=90=84=E8=87=AA=E7=9A=84=E5=8C=85=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anyUtil/any_to_float_x.go | 7 +++---- anyUtil/any_to_float_x_test.go | 9 ++++----- anyUtil/any_to_int_x.go | 13 ++++++------ anyUtil/any_to_int_x_test.go | 23 ++++++++++----------- anyUtil/any_to_uint_x.go | 19 +++++++++-------- anyUtil/any_to_uint_x_test.go | 37 +++++++++++++++++----------------- anyUtil/err_code.go | 24 ++++++++++++++++++++++ byteUtil/err_code.go | 1 + cryptoUtil/err_code.go | 1 + emojiUtil/err_code.go | 1 + errorcode.go | 22 -------------------- floatUtil/err_code.go | 1 + jsonUtil/err_code.go | 16 +++++++++++++++ jsonUtil/to_float.go | 11 +++++----- jsonUtil/to_float_test.go | 9 ++++----- jsonUtil/to_int.go | 11 +++++----- jsonUtil/to_int_test.go | 5 ++--- jsonUtil/to_uint.go | 11 +++++----- jsonUtil/to_uint_test.go | 5 ++--- mapUtil/err_code.go | 1 + mathUtil/err_code.go | 1 + sliceUtil/err_code.go | 1 + strUtil/err_code.go | 1 + validUtil/err_code.go | 1 + 24 files changed, 123 insertions(+), 108 deletions(-) create mode 100644 anyUtil/err_code.go create mode 100644 byteUtil/err_code.go create mode 100644 cryptoUtil/err_code.go create mode 100644 emojiUtil/err_code.go delete mode 100644 errorcode.go create mode 100644 floatUtil/err_code.go create mode 100644 jsonUtil/err_code.go create mode 100644 mapUtil/err_code.go create mode 100644 mathUtil/err_code.go create mode 100644 sliceUtil/err_code.go create mode 100644 strUtil/err_code.go create mode 100644 validUtil/err_code.go diff --git a/anyUtil/any_to_float_x.go b/anyUtil/any_to_float_x.go index f42b5bf..08242ed 100644 --- a/anyUtil/any_to_float_x.go +++ b/anyUtil/any_to_float_x.go @@ -1,7 +1,6 @@ package anyUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "math" "reflect" "strconv" @@ -14,7 +13,7 @@ func AnyToFloat32(i any) (float32, error) { return 0, err } if f64 < -math.MaxFloat32 || f64 > math.MaxFloat32 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return float32(f64), nil } @@ -39,7 +38,7 @@ func AnyToFloat64(i any) (float64, error) { case reflect.String: floatValue, err := strconv.ParseFloat(v.String(), 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return floatValue, nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -55,6 +54,6 @@ func AnyToFloat64(i any) (float64, error) { return 0, nil } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/anyUtil/any_to_float_x_test.go b/anyUtil/any_to_float_x_test.go index 3d0a55e..8cc7669 100644 --- a/anyUtil/any_to_float_x_test.go +++ b/anyUtil/any_to_float_x_test.go @@ -1,7 +1,6 @@ package anyUtil import ( - go_easy_utils "github.com/jefferyjob/go-easy-utils/v2" "math" "testing" ) @@ -30,8 +29,8 @@ func TestAnyToFloat32(t *testing.T) { {uint32(32), 32, nil}, {uint64(64), 64, nil}, {"3.14", 3.14, nil}, - {math.MaxFloat64, 0, go_easy_utils.ErrValOut}, - {make(chan int), 0, go_easy_utils.ErrType}, + {math.MaxFloat64, 0, ErrValOut}, + {make(chan int), 0, ErrType}, } for _, test := range tests { @@ -79,8 +78,8 @@ func TestAnyToFloat64(t *testing.T) { {complex128(1 + 2i), 1, nil}, {&iPtr, 90, nil}, {(*int)(nil), 0, nil}, - {"abc", 0, go_easy_utils.ErrSyntax}, - {[]int{}, 0, go_easy_utils.ErrType}, + {"abc", 0, ErrSyntax}, + {[]int{}, 0, ErrType}, } for _, test := range tests { diff --git a/anyUtil/any_to_int_x.go b/anyUtil/any_to_int_x.go index a42bdcf..ec73533 100644 --- a/anyUtil/any_to_int_x.go +++ b/anyUtil/any_to_int_x.go @@ -1,7 +1,6 @@ package anyUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "math" "reflect" "strconv" @@ -16,7 +15,7 @@ func AnyToInt(i any) (int, error) { // int 兼容32位和64位系统 if int64(int(v)) != v { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return int(v), nil @@ -29,7 +28,7 @@ func AnyToInt8(i any) (int8, error) { return 0, err } if value < math.MinInt8 || value > math.MaxInt8 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return int8(value), nil } @@ -41,7 +40,7 @@ func AnyToInt16(i any) (int16, error) { return 0, err } if value < math.MinInt16 || value > math.MaxInt16 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return int16(value), nil } @@ -53,7 +52,7 @@ func AnyToInt32(i any) (int32, error) { return 0, err } if value < math.MinInt32 || value > math.MaxInt32 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return int32(value), nil } @@ -78,7 +77,7 @@ func AnyToInt64(i any) (int64, error) { case reflect.String: intValue, err := strconv.ParseInt(v.String(), 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return intValue, nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -96,6 +95,6 @@ func AnyToInt64(i any) (int64, error) { return 0, nil } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/anyUtil/any_to_int_x_test.go b/anyUtil/any_to_int_x_test.go index 6c75509..e7405d5 100644 --- a/anyUtil/any_to_int_x_test.go +++ b/anyUtil/any_to_int_x_test.go @@ -2,7 +2,6 @@ package anyUtil import ( "errors" - "github.com/jefferyjob/go-easy-utils/v2" "math" "testing" ) @@ -32,7 +31,7 @@ func TestAnyToInt(t *testing.T) { {input: float32(123.45), expected: 123, err: nil}, {input: float64(123.45), expected: 123, err: nil}, {input: "123", expected: 123, err: nil}, - {input: "abc", expected: 0, err: go_easy_utils.ErrSyntax}, + {input: "abc", expected: 0, err: ErrSyntax}, } for _, tc := range testCases { @@ -83,13 +82,13 @@ func TestAnyToInt8(t *testing.T) { name: "positive integer out of range", input: 128, expected: 0, - err: go_easy_utils.ErrValOut, + err: ErrValOut, }, { name: "negative integer out of range", input: -129, expected: 0, - err: go_easy_utils.ErrValOut, + err: ErrValOut, }, { name: "float", @@ -107,13 +106,13 @@ func TestAnyToInt8(t *testing.T) { name: "string out of range", input: "128", expected: 0, - err: go_easy_utils.ErrValOut, + err: ErrValOut, }, { name: "invalid string", input: "invalid", expected: 0, - err: go_easy_utils.ErrSyntax, + err: ErrSyntax, }, } @@ -159,8 +158,8 @@ func TestAnyToInt16(t *testing.T) { {float32(123.45), 123, nil}, {float64(123.45), 123, nil}, {"12345", 12345, nil}, - {math.MinInt16 - 1, 0, go_easy_utils.ErrValOut}, - {"not a number", 0, go_easy_utils.ErrSyntax}, + {math.MinInt16 - 1, 0, ErrValOut}, + {"not a number", 0, ErrSyntax}, } for _, tt := range tests { @@ -184,13 +183,13 @@ func TestAnyToInt32(t *testing.T) { }{ {int(123), 123, nil}, {int64(2147483647), 2147483647, nil}, - {int64(2147483648), 0, go_easy_utils.ErrValOut}, + {int64(2147483648), 0, ErrValOut}, {int64(-2147483648), -2147483648, nil}, - {int64(-2147483649), 0, go_easy_utils.ErrValOut}, + {int64(-2147483649), 0, ErrValOut}, {float64(123.45), 123, nil}, {"123", 123, nil}, - {"-2147483649", 0, go_easy_utils.ErrValOut}, - {struct{}{}, 0, go_easy_utils.ErrType}, + {"-2147483649", 0, ErrValOut}, + {struct{}{}, 0, ErrType}, } for _, testCase := range testCases { diff --git a/anyUtil/any_to_uint_x.go b/anyUtil/any_to_uint_x.go index 2e9e43b..b3dbcd8 100644 --- a/anyUtil/any_to_uint_x.go +++ b/anyUtil/any_to_uint_x.go @@ -1,7 +1,6 @@ package anyUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "math" "reflect" "strconv" @@ -16,7 +15,7 @@ func AnyToUint(i any) (uint, error) { // uint 兼容32位和64位系统 if uint64(uint(v)) != v { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return uint(v), nil @@ -29,7 +28,7 @@ func AnyToUint8(i any) (uint8, error) { return 0, err } if value > math.MaxUint8 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return uint8(value), nil } @@ -41,7 +40,7 @@ func AnyToUint16(i any) (uint16, error) { return 0, err } if value > math.MaxUint16 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return uint16(value), nil } @@ -53,7 +52,7 @@ func AnyToUint32(i any) (uint32, error) { return 0, err } if value > math.MaxUint32 { - return 0, go_easy_utils.ErrValOut + return 0, ErrValOut } return uint32(value), nil } @@ -78,26 +77,26 @@ func AnyToUint64(i any) (uint64, error) { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: intValue := v.Int() if intValue < 0 { - return 0, go_easy_utils.ErrUnsignedInt + return 0, ErrUnsignedInt } return uint64(intValue), nil case reflect.Float32, reflect.Float64: floatValue := v.Float() if floatValue < 0 { - return 0, go_easy_utils.ErrUnsignedInt + return 0, ErrUnsignedInt } return uint64(floatValue), nil case reflect.Complex64, reflect.Complex128: realValue := real(v.Complex()) if realValue < 0 { - return 0, go_easy_utils.ErrUnsignedInt + return 0, ErrUnsignedInt } return uint64(realValue), nil case reflect.String: strValue := v.String() uintValue, err := strconv.ParseUint(strValue, 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return uintValue, nil case reflect.Bool: @@ -107,6 +106,6 @@ func AnyToUint64(i any) (uint64, error) { return 0, nil } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/anyUtil/any_to_uint_x_test.go b/anyUtil/any_to_uint_x_test.go index ae47560..09f80d7 100644 --- a/anyUtil/any_to_uint_x_test.go +++ b/anyUtil/any_to_uint_x_test.go @@ -1,7 +1,6 @@ package anyUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "reflect" "testing" ) @@ -14,11 +13,11 @@ func TestAnyToUint(t *testing.T) { err error }{ {10, 10, nil}, - {-5, 0, go_easy_utils.ErrUnsignedInt}, + {-5, 0, ErrUnsignedInt}, {"20", 20, nil}, {1.5, 1, nil}, {2.5, 2, nil}, - {make(chan int), 0, go_easy_utils.ErrType}, + {make(chan int), 0, ErrType}, } // Test loop @@ -39,10 +38,10 @@ func TestAnyToUint8(t *testing.T) { err error }{ {10, 10, nil}, - {300, 0, go_easy_utils.ErrValOut}, + {300, 0, ErrValOut}, {"20", 20, nil}, {1.5, 1, nil}, - {make(chan int), 0, go_easy_utils.ErrType}, + {make(chan int), 0, ErrType}, } // Test loop @@ -63,10 +62,10 @@ func TestAnyToUint16(t *testing.T) { err error }{ {10, 10, nil}, - {70000, 0, go_easy_utils.ErrValOut}, + {70000, 0, ErrValOut}, {"20", 20, nil}, {1.5, 1, nil}, - {make(chan int), 0, go_easy_utils.ErrType}, + {make(chan int), 0, ErrType}, } // Test loop @@ -87,10 +86,10 @@ func TestAnyToUint32(t *testing.T) { err error }{ {10, 10, nil}, - {5000000000, 0, go_easy_utils.ErrValOut}, + {5000000000, 0, ErrValOut}, {"20", 20, nil}, {1.5, 1, nil}, - {make(chan int), 0, go_easy_utils.ErrType}, + {make(chan int), 0, ErrType}, } // Test loop @@ -115,37 +114,37 @@ func TestAnyToUint64(t *testing.T) { { name: "Test -float32", input: float32(-0.1), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -float64", input: float64(-0.2), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -int", input: int(-1), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -int8", input: int8(-2), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -int16", input: int16(-3), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -int32", input: int32(-4), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test -int64", input: int64(-5), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test uint", @@ -220,7 +219,7 @@ func TestAnyToUint64(t *testing.T) { { name: "Test invalid string", input: "not a number", - wantError: go_easy_utils.ErrSyntax, + wantError: ErrSyntax, }, { name: "Test nil pointer", @@ -251,12 +250,12 @@ func TestAnyToUint64(t *testing.T) { { name: "test -complex", input: complex(-1, -1), - wantError: go_easy_utils.ErrUnsignedInt, + wantError: ErrUnsignedInt, }, { name: "Test invalid type", input: make(chan int), - wantError: go_easy_utils.ErrType, + wantError: ErrType, }, } diff --git a/anyUtil/err_code.go b/anyUtil/err_code.go new file mode 100644 index 0000000..ef3dab8 --- /dev/null +++ b/anyUtil/err_code.go @@ -0,0 +1,24 @@ +package anyUtil + +import ( + "errors" + "strconv" +) + +var ( + // ErrSyntax indicates that a value does not have the right syntax for the target type + // 指示值不具有目标类型的正确语法 + ErrSyntax = strconv.ErrSyntax + + // ErrType indicates that a value does not have the right syntax for the target type + // 指示值不具有目标类型的正确语法 + ErrType = errors.New("unsupported type") + + // ErrValOut Indicates that the range corresponding to the type is exceeded + // 表示超出了类型对应的范围 + ErrValOut = errors.New("value out of range") + + // ErrUnsignedInt The identity type is negative, so it cannot be converted to an unsigned integer + // 标识类型为负数,所以无法转为无符号的整型 + ErrUnsignedInt = errors.New("cannot convert negative value to unsigned integer") +) diff --git a/byteUtil/err_code.go b/byteUtil/err_code.go new file mode 100644 index 0000000..b9da58c --- /dev/null +++ b/byteUtil/err_code.go @@ -0,0 +1 @@ +package byteUtil diff --git a/cryptoUtil/err_code.go b/cryptoUtil/err_code.go new file mode 100644 index 0000000..751ffd7 --- /dev/null +++ b/cryptoUtil/err_code.go @@ -0,0 +1 @@ +package cryptoUtil diff --git a/emojiUtil/err_code.go b/emojiUtil/err_code.go new file mode 100644 index 0000000..b58661e --- /dev/null +++ b/emojiUtil/err_code.go @@ -0,0 +1 @@ +package emojiUtil diff --git a/errorcode.go b/errorcode.go deleted file mode 100644 index 8ffacfa..0000000 --- a/errorcode.go +++ /dev/null @@ -1,22 +0,0 @@ -package go_easy_utils - -import ( - "errors" - "strconv" -) - -// ErrSyntax indicates that a value does not have the right syntax for the target type -// 指示值不具有目标类型的正确语法 -var ErrSyntax = strconv.ErrSyntax - -// ErrType indicates that a value does not have the right syntax for the target type -// 指示值不具有目标类型的正确语法 -var ErrType = errors.New("unsupported type") - -// ErrValOut Indicates that the range corresponding to the type is exceeded -// 表示超出了类型对应的范围 -var ErrValOut = errors.New("value out of range") - -// ErrUnsignedInt The identity type is negative, so it cannot be converted to an unsigned integer -// 标识类型为负数,所以无法转为无符号的整型 -var ErrUnsignedInt = errors.New("cannot convert negative value to unsigned integer") diff --git a/floatUtil/err_code.go b/floatUtil/err_code.go new file mode 100644 index 0000000..8a0c512 --- /dev/null +++ b/floatUtil/err_code.go @@ -0,0 +1 @@ +package floatUtil diff --git a/jsonUtil/err_code.go b/jsonUtil/err_code.go new file mode 100644 index 0000000..8b676c8 --- /dev/null +++ b/jsonUtil/err_code.go @@ -0,0 +1,16 @@ +package jsonUtil + +import ( + "errors" + "strconv" +) + +var ( + // ErrSyntax indicates that a value does not have the right syntax for the target type + // 指示值不具有目标类型的正确语法 + ErrSyntax = strconv.ErrSyntax + + // ErrType indicates that a value does not have the right syntax for the target type + // 指示值不具有目标类型的正确语法 + ErrType = errors.New("unsupported type") +) diff --git a/jsonUtil/to_float.go b/jsonUtil/to_float.go index 10e87c2..b8a52eb 100644 --- a/jsonUtil/to_float.go +++ b/jsonUtil/to_float.go @@ -1,7 +1,6 @@ package jsonUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "reflect" "strconv" ) @@ -27,7 +26,7 @@ func toFloat64(i any) (float64, error) { case string: floatValue, err := strconv.ParseFloat(v, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return floatValue, nil case uint: @@ -67,7 +66,7 @@ func toFloat64(i any) (float64, error) { //case *string: // floatValue, err := strconv.ParseFloat(*v, 64) // if err != nil { - // return 0, go_easy_utils.ErrSyntax + // return 0, ErrSyntax // } // return floatValue, nil //case *uint: @@ -101,7 +100,7 @@ func toFloat64(i any) (float64, error) { // return 0, nil // } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } @@ -127,7 +126,7 @@ func toFloat64Reflect(i any) (float64, error) { } floatValue, err := strconv.ParseFloat(v.String(), 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return floatValue, nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -145,6 +144,6 @@ func toFloat64Reflect(i any) (float64, error) { //case reflect.Ptr, reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Slice: // return 0, nil default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/jsonUtil/to_float_test.go b/jsonUtil/to_float_test.go index 0db7fb7..c6b4418 100644 --- a/jsonUtil/to_float_test.go +++ b/jsonUtil/to_float_test.go @@ -1,7 +1,6 @@ package jsonUtil import ( - go_easy_utils "github.com/jefferyjob/go-easy-utils/v2" "reflect" "testing" ) @@ -44,8 +43,8 @@ func TestToFloat64(t *testing.T) { {true, 1, nil}, {false, 0, nil}, {(*bool)(nil), 0, nil}, - {make(chan int), 0, go_easy_utils.ErrType}, - {"abc", 0, go_easy_utils.ErrSyntax}, + {make(chan int), 0, ErrType}, + {"abc", 0, ErrSyntax}, } for _, tc := range testCases { @@ -90,7 +89,7 @@ func TestToFloat64Pointer(t *testing.T) { name: "invalid string input", input: stringPtr("abc"), expectedValue: 0, - expectedError: go_easy_utils.ErrSyntax, + expectedError: ErrSyntax, }, { name: "valid string input", @@ -186,7 +185,7 @@ func TestToFloat64Pointer(t *testing.T) { name: "unsupported input type", input: "unsupported", expectedValue: 0, - expectedError: go_easy_utils.ErrSyntax, + expectedError: ErrSyntax, }, } diff --git a/jsonUtil/to_int.go b/jsonUtil/to_int.go index e225070..a7e20ca 100644 --- a/jsonUtil/to_int.go +++ b/jsonUtil/to_int.go @@ -1,7 +1,6 @@ package jsonUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "reflect" "strconv" ) @@ -46,7 +45,7 @@ func toInt64(i any) (int64, error) { case string: intValue, err := strconv.ParseInt(v, 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return intValue, nil case int: @@ -97,7 +96,7 @@ func toInt64(i any) (int64, error) { // } // intValue, err := strconv.ParseInt(*v, 10, 64) // if err != nil { - // return 0, go_easy_utils.ErrSyntax + // return 0, ErrSyntax // } // return intValue, nil //case *int: @@ -111,7 +110,7 @@ func toInt64(i any) (int64, error) { //case *int64: // return *v, nil default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } @@ -137,7 +136,7 @@ func toInt64Reflect(i any) (int64, error) { } intValue, err := strconv.ParseInt(v.String(), 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return intValue, nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -155,6 +154,6 @@ func toInt64Reflect(i any) (int64, error) { return 0, nil } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/jsonUtil/to_int_test.go b/jsonUtil/to_int_test.go index f349c82..c814b81 100644 --- a/jsonUtil/to_int_test.go +++ b/jsonUtil/to_int_test.go @@ -1,7 +1,6 @@ package jsonUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "testing" ) @@ -31,8 +30,8 @@ func TestToInt64(t *testing.T) { {complex64(1 + 2i), 1, nil}, {complex128(1 + 2i), 1, nil}, {nil, 0, nil}, - {"not a number", 0, go_easy_utils.ErrSyntax}, - {make(chan int), 0, go_easy_utils.ErrType}, + {"not a number", 0, ErrSyntax}, + {make(chan int), 0, ErrType}, } for _, tt := range tests { diff --git a/jsonUtil/to_uint.go b/jsonUtil/to_uint.go index 01ed7eb..641f1ec 100644 --- a/jsonUtil/to_uint.go +++ b/jsonUtil/to_uint.go @@ -1,7 +1,6 @@ package jsonUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "reflect" "strconv" ) @@ -43,7 +42,7 @@ func toUint64(i any) (uint64, error) { case string: intValue, err := strconv.ParseUint(v, 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return intValue, nil case bool: @@ -110,7 +109,7 @@ func toUint64(i any) (uint64, error) { //case *string: // intValue, err := strconv.ParseUint(*v, 10, 64) // if err != nil { - // return 0, go_easy_utils.ErrSyntax + // return 0, ErrSyntax // } // return intValue, nil //case *bool: @@ -155,7 +154,7 @@ func toUint64(i any) (uint64, error) { // } // return uint64(*v), nil default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } @@ -199,7 +198,7 @@ func toUint64Reflect(i any) (uint64, error) { } uintValue, err := strconv.ParseUint(v.String(), 10, 64) if err != nil { - return 0, go_easy_utils.ErrSyntax + return 0, ErrSyntax } return uintValue, nil case reflect.Bool: @@ -209,6 +208,6 @@ func toUint64Reflect(i any) (uint64, error) { return 0, nil } default: - return 0, go_easy_utils.ErrType + return 0, ErrType } } diff --git a/jsonUtil/to_uint_test.go b/jsonUtil/to_uint_test.go index 3660416..778ef59 100644 --- a/jsonUtil/to_uint_test.go +++ b/jsonUtil/to_uint_test.go @@ -1,7 +1,6 @@ package jsonUtil import ( - "github.com/jefferyjob/go-easy-utils/v2" "testing" ) @@ -125,7 +124,7 @@ func TestToUint64(t *testing.T) { { name: "Test invalid string", input: "not a number", - wantError: go_easy_utils.ErrSyntax, + wantError: ErrSyntax, }, { name: "Test nil pointer", @@ -146,7 +145,7 @@ func TestToUint64(t *testing.T) { { name: "Test invalid type", input: make(chan int), - wantError: go_easy_utils.ErrType, + wantError: ErrType, }, } diff --git a/mapUtil/err_code.go b/mapUtil/err_code.go new file mode 100644 index 0000000..061f039 --- /dev/null +++ b/mapUtil/err_code.go @@ -0,0 +1 @@ +package mapUtil diff --git a/mathUtil/err_code.go b/mathUtil/err_code.go new file mode 100644 index 0000000..ca018f1 --- /dev/null +++ b/mathUtil/err_code.go @@ -0,0 +1 @@ +package mathUtil diff --git a/sliceUtil/err_code.go b/sliceUtil/err_code.go new file mode 100644 index 0000000..5189997 --- /dev/null +++ b/sliceUtil/err_code.go @@ -0,0 +1 @@ +package sliceUtil diff --git a/strUtil/err_code.go b/strUtil/err_code.go new file mode 100644 index 0000000..a0decbe --- /dev/null +++ b/strUtil/err_code.go @@ -0,0 +1 @@ +package strUtil diff --git a/validUtil/err_code.go b/validUtil/err_code.go new file mode 100644 index 0000000..42333c1 --- /dev/null +++ b/validUtil/err_code.go @@ -0,0 +1 @@ +package validUtil From 204409b1e8721846f57e15a75eee46d85dc8e3ec Mon Sep 17 00:00:00 2001 From: libin Date: Wed, 3 Apr 2024 10:57:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?err=20code=20=E8=BF=81=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=E5=90=84=E8=87=AA=E5=8C=85=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19d6581..1576440 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,6 @@ func main() { ## Sponsorship and support -`GoEasyUtils` Thank JetBrains for their support +`go-easy-utils` Thank JetBrains for their support JetBrains \ No newline at end of file