- 达达与美团配送的接口修改为较正式参数
This commit is contained in:
@@ -2,9 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -172,14 +170,7 @@ func CallFuncRetryAsync(handler func(int) error, duration time.Duration, retryCo
|
||||
func GenerateGetURL(baseURL, apiStr string, params map[string]interface{}) string {
|
||||
queryString := ""
|
||||
if params != nil {
|
||||
for k, v := range params {
|
||||
if queryString == "" {
|
||||
queryString = "?"
|
||||
} else {
|
||||
queryString += "&"
|
||||
}
|
||||
queryString += k + "=" + url.QueryEscape(fmt.Sprint(v))
|
||||
}
|
||||
queryString = "?" + Map2URLValues(params).Encode()
|
||||
}
|
||||
if apiStr != "" {
|
||||
return baseURL + "/" + apiStr + queryString
|
||||
|
||||
@@ -235,3 +235,20 @@ func TestLimitUTF8StringLen(t *testing.T) {
|
||||
t.Log(LimitUTF8StringLen("a大家好1234567", 8))
|
||||
t.Log(LimitMixedStringLen("a大家好1234567", 8))
|
||||
}
|
||||
|
||||
func TestGenerateGetURL(t *testing.T) {
|
||||
fullURL := GenerateGetURL("http://www.163.com", "api", map[string]interface{}{
|
||||
"k1": "v1",
|
||||
"k2": 2,
|
||||
})
|
||||
t.Log(fullURL)
|
||||
if fullURL != "http://www.163.com/api?k1=v1&k2=2" {
|
||||
t.Fatal("GenerateGetURL错误")
|
||||
}
|
||||
|
||||
fullURL = GenerateGetURL("http://www.163.com", "api", nil)
|
||||
t.Log(fullURL)
|
||||
if fullURL != "http://www.163.com/api" {
|
||||
t.Fatal("GenerateGetURL错误")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user