From 0506319ef064d8b43ab590778236a4ce926e9605 Mon Sep 17 00:00:00 2001 From: guzeng Date: Mon, 14 Nov 2022 17:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0MAP=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E8=BD=AC=E5=A4=A7=E9=A9=BC=E5=B3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 15 +++++++++++++++ map_test.go | 6 ++++++ math.go | 13 ++++++++++++- math_test.go | 6 ++++++ string_test.go | 6 ++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/map.go b/map.go index ff6d367..cfaa53d 100644 --- a/map.go +++ b/map.go @@ -277,3 +277,18 @@ func MapPage(pageNum, pageSize int, MapDate []map[string]interface{}) []map[stri } return MapDate[stat:end] } + +/** + * MAP索引转大驼峰 + * gz + */ +func SetMapFirstToUpper(info map[string]interface{}) map[string]interface{} { + var ret map[string]interface{} + if len(info) > 0 { + ret = make(map[string]interface{}) + for k, v := range info { + ret[StrFirstToUpper(k)] = v + } + } + return ret +} diff --git a/map_test.go b/map_test.go index c2dfbad..8cd4ccb 100644 --- a/map_test.go +++ b/map_test.go @@ -22,3 +22,9 @@ func Test_HttpBuildQuery(t *testing.T) { t.Log(ret) } + +func Test_SetMapFirstToUpper(t *testing.T) { + a := map[string]interface{}{"id": "11", "name": "8", "a_c": 99, "price": "2.3", "cc_dd_ee": 22} + ret := SetMapFirstToUpper(a) + t.Log(ret) +} diff --git a/math.go b/math.go index 341ab3e..eb7b10f 100755 --- a/math.go +++ b/math.go @@ -134,7 +134,7 @@ func FloatQuo(str ...interface{}) float64 { /** * 十进制转十六进制 */ -func TenToHex(ten int) string { +func DecToHex(ten int) string { m := 0 hex := make([]int, 0) for { @@ -156,3 +156,14 @@ func TenToHex(ten int) string { } return strings.Join(hexStr, "") } + +/** + * 十六进制转十进制 + */ +func HexToDec(val string) (int, error) { + n, err := strconv.ParseUint(val, 16, 64) + if err != nil { + return 0, err + } + return int(n), nil +} diff --git a/math_test.go b/math_test.go index a550fd5..9077fff 100644 --- a/math_test.go +++ b/math_test.go @@ -48,3 +48,9 @@ func Test_TenToHex(t *testing.T) { ret := TenToHex(str1) t.Log(ret) } + +func Test_HexToTen(t *testing.T) { + str := "29B79F0D" + ret, err := HexToTen(str) + t.Log(ret, err) +} diff --git a/string_test.go b/string_test.go index 6f4dddd..513e889 100755 --- a/string_test.go +++ b/string_test.go @@ -47,3 +47,9 @@ func Test_StrFirstToUpper(t *testing.T) { ret := StrFirstToUpper(str) t.Log(ret) } + +func Test_ToInt(t *testing.T) { + var str string = "sd23455667,123456789aq,qq123456789" + ret := ToInt(str) + t.Log(ret) +}