Browse Source

增加MAP索引转大驼峰

master v0.7.0
guzeng 2 years ago
parent
commit
0506319ef0
5 changed files with 45 additions and 1 deletions
  1. +15
    -0
      map.go
  2. +6
    -0
      map_test.go
  3. +12
    -1
      math.go
  4. +6
    -0
      math_test.go
  5. +6
    -0
      string_test.go

+ 15
- 0
map.go View File

@ -277,3 +277,18 @@ func MapPage(pageNum, pageSize int, MapDate []map[string]interface{}) []map[stri
} }
return MapDate[stat:end] 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
}

+ 6
- 0
map_test.go View File

@ -22,3 +22,9 @@ func Test_HttpBuildQuery(t *testing.T) {
t.Log(ret) 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)
}

+ 12
- 1
math.go View File

@ -134,7 +134,7 @@ func FloatQuo(str ...interface{}) float64 {
/** /**
* 十进制转十六进制 * 十进制转十六进制
*/ */
func TenToHex(ten int) string {
func DecToHex(ten int) string {
m := 0 m := 0
hex := make([]int, 0) hex := make([]int, 0)
for { for {
@ -156,3 +156,14 @@ func TenToHex(ten int) string {
} }
return strings.Join(hexStr, "") 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
}

+ 6
- 0
math_test.go View File

@ -48,3 +48,9 @@ func Test_TenToHex(t *testing.T) {
ret := TenToHex(str1) ret := TenToHex(str1)
t.Log(ret) t.Log(ret)
} }
func Test_HexToTen(t *testing.T) {
str := "29B79F0D"
ret, err := HexToTen(str)
t.Log(ret, err)
}

+ 6
- 0
string_test.go View File

@ -47,3 +47,9 @@ func Test_StrFirstToUpper(t *testing.T) {
ret := StrFirstToUpper(str) ret := StrFirstToUpper(str)
t.Log(ret) t.Log(ret)
} }
func Test_ToInt(t *testing.T) {
var str string = "sd23455667,123456789aq,qq123456789"
ret := ToInt(str)
t.Log(ret)
}

Loading…
Cancel
Save