From e4f8672814a5ee1215107a8905cc63bdd5fa335b Mon Sep 17 00:00:00 2001 From: wuyongyuan <270458160@qq.com> Date: Thu, 14 Oct 2021 20:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=94=E5=9B=9E=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E5=9C=A8=E5=88=87=E7=89=87=E4=B8=AD=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=B4=A2=E5=BC=95=E5=92=8C=E4=B8=8D=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=8E=92=E5=BA=8Fmap=E5=AD=97=E5=85=B8=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 26 ++++++++++++++++++++++++++ string.go | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/map.go b/map.go index 91434b9..6343157 100644 --- a/map.go +++ b/map.go @@ -119,3 +119,29 @@ func HttpBuildQuery(data map[string]string) string { return strings.Trim(query, "&") } + +/** + * 对map进行拼接 + * @param data map[string]string + * @2021/10/14 + * @wyy + */ +func HttpBuildStringQuery(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 { + if value != "" && data[value] != "" { + query += StringJoin(value, "=", data[value], "&") + } + } + + return strings.Trim(query, "&") +} diff --git a/string.go b/string.go index 49da990..b674a23 100755 --- a/string.go +++ b/string.go @@ -203,6 +203,26 @@ func IsInStringArray(arr []string, str string) bool { return isIn } +/** + * 字符串在字符切片中对应索引 + */ +func InStringArrayIndex(arr []string, str string) int { + // var isIn bool = false + length := len(arr) + if length < 1 { + return -1 + } + var index int = -1 + for k, item := range arr { + if item == str { + // isIn = true + index = k + break + } + } + return index +} + /* * 删除多余空格 * 2019/05/05