|
|
@ -2,6 +2,8 @@ package helper |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"sort" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
|
func MergeStringMap(x, y map[string]string) map[string]string { |
|
|
@ -65,13 +67,13 @@ func ToMapStringArray(x interface{}) ([]map[string]string, error) { |
|
|
|
/** |
|
|
|
* 将map[string]string数组转成map[string]interface数组 |
|
|
|
*/ |
|
|
|
func MapStringToInterfaceArr(src []map[string]string)([]map[string]interface{}){ |
|
|
|
func MapStringToInterfaceArr(src []map[string]string) []map[string]interface{} { |
|
|
|
var dest []map[string]interface{} |
|
|
|
|
|
|
|
for i := range src { |
|
|
|
m := src[i] |
|
|
|
n := make(map[string]interface{}) |
|
|
|
for k,v := range m { |
|
|
|
for k, v := range m { |
|
|
|
n[k] = interface{}(v) |
|
|
|
} |
|
|
|
dest = append(dest, n) |
|
|
@ -83,11 +85,35 @@ func MapStringToInterfaceArr(src []map[string]string)([]map[string]interface{}){ |
|
|
|
/** |
|
|
|
* 将map[string]string转成map[string]interface |
|
|
|
*/ |
|
|
|
func MapStringToInterface(src map[string]string)(map[string]interface{}){ |
|
|
|
func MapStringToInterface(src map[string]string) map[string]interface{} { |
|
|
|
target := make(map[string]interface{}) |
|
|
|
for k,v := range src { |
|
|
|
for k, v := range src { |
|
|
|
target[k] = interface{}(v) |
|
|
|
} |
|
|
|
|
|
|
|
return target |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 对map进行字典序排序 |
|
|
|
* @param data map[string]string |
|
|
|
* @2020/12/28 |
|
|
|
* @linsen |
|
|
|
*/ |
|
|
|
func HttpBuildQuery(data map[string]string) string { |
|
|
|
|
|
|
|
keySlice := []string{} |
|
|
|
|
|
|
|
for k, _ := range data { |
|
|
|
keySlice = append(keySlice, k) |
|
|
|
} |
|
|
|
sort.Strings(keySlice) //排序字符串
|
|
|
|
|
|
|
|
var query string |
|
|
|
|
|
|
|
for _, value := range keySlice { |
|
|
|
query += StringJoin(value, "=", data[value], "&") |
|
|
|
} |
|
|
|
|
|
|
|
return strings.Trim(query, "&") |
|
|
|
} |